0. Hàm load các thư viện số học, dữ liệu, mảng và biểu đồ
import numpy as np
import pandas as pd
#pd.__version__
import seaborn as sns
from matplotlib import pyplot as plt
from statsmodels.tsa.api import ExponentialSmoothing, SimpleExpSmoothing, Holt
from sklearn.linear_model import LinearRegression
import warnings
warnings.filterwarnings('ignore')
1. Hàm load dữ liệu từ file CSV, định dạng số cột, dòng
df = pd.read_csv(r"C:\Python311\workspaces\m6B45.csv")
pd.set_option("display.max_rows",df.shape[0]+1)
pd.set_option("display.max_columns",60)
df
| Date | S01 | S02 | S03 | S04 | S05 | S06 | S07 | S08 | S09 | S10 | S11 | S12 | S13 | S14 | S15 | S16 | S17 | S18 | S19 | S20 | S21 | S22 | S23 | S24 | S25 | S26 | S27 | S28 | S29 | S30 | S31 | S32 | S33 | S34 | S35 | S36 | S37 | S38 | S39 | S40 | S41 | S42 | S43 | S44 | S45 | ST | Link | Type | BD | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 24/9/2023 | 151 | 137 | 136 | 160 | 159 | 158 | 157 | 143 | 140 | 158 | 145 | 138 | 151 | 132 | 132 | 146 | 136 | 151 | 167 | 145 | 143 | 150 | 143 | 162 | 150 | 141 | 152 | 148 | 139 | 161 | 144 | 137 | 149 | 136 | 156 | 135 | 162 | 132 | 136 | 144 | 149 | 132 | 137 | 168 | 140 | 146.400000 | https://vietlott/vn/vi/choi/mega-6-45/thong-ke... | M6B45 | 18/07/2016 |
| 1 | 27/9/2023 | 151 | 137 | 137 | 161 | 159 | 158 | 157 | 144 | 140 | 158 | 145 | 139 | 151 | 132 | 132 | 146 | 136 | 151 | 167 | 145 | 143 | 151 | 144 | 162 | 150 | 141 | 153 | 148 | 139 | 163 | 144 | 137 | 149 | 136 | 156 | 136 | 163 | 132 | 137 | 144 | 149 | 132 | 137 | 168 | 140 | 146.670000 | NaN | NaN | NaN |
| 2 | 29/9/2023 | 151 | 138 | 137 | 161 | 159 | 158 | 157 | 145 | 140 | 158 | 145 | 139 | 151 | 132 | 132 | 146 | 136 | 151 | 167 | 145 | 143 | 151 | 144 | 163 | 150 | 141 | 154 | 148 | 139 | 164 | 144 | 137 | 149 | 136 | 156 | 136 | 163 | 132 | 137 | 144 | 149 | 132 | 138 | 168 | 140 | 146.800000 | NaN | NaN | NaN |
| 3 | 1/10/2023 | 151 | 139 | 137 | 161 | 159 | 158 | 157 | 145 | 140 | 158 | 146 | 139 | 152 | 132 | 132 | 147 | 136 | 151 | 167 | 145 | 143 | 151 | 144 | 163 | 150 | 141 | 154 | 148 | 139 | 164 | 144 | 137 | 149 | 136 | 156 | 136 | 163 | 132 | 137 | 144 | 150 | 132 | 139 | 168 | 140 | 146.930000 | NaN | NaN | NaN |
| 4 | 4/10/2023 | 151 | 139 | 137 | 161 | 159 | 158 | 158 | 145 | 140 | 158 | 146 | 139 | 152 | 132 | 132 | 147 | 137 | 151 | 167 | 145 | 144 | 151 | 144 | 163 | 150 | 141 | 154 | 148 | 139 | 164 | 144 | 138 | 149 | 136 | 156 | 136 | 163 | 132 | 137 | 145 | 150 | 132 | 139 | 168 | 141 | 147.070000 | NaN | NaN | NaN |
| 5 | 6/10/2023 | 151 | 139 | 137 | 161 | 159 | 158 | 158 | 145 | 140 | 158 | 146 | 139 | 152 | 132 | 132 | 147 | 137 | 152 | 168 | 145 | 144 | 151 | 144 | 164 | 150 | 141 | 154 | 149 | 139 | 164 | 144 | 138 | 150 | 136 | 156 | 136 | 163 | 132 | 137 | 146 | 150 | 132 | 139 | 168 | 141 | 147.200000 | NaN | NaN | NaN |
| 6 | 8/10/2023 | 151 | 139 | 137 | 162 | 159 | 158 | 158 | 145 | 140 | 158 | 146 | 139 | 152 | 132 | 132 | 148 | 137 | 152 | 168 | 145 | 144 | 152 | 144 | 164 | 150 | 141 | 154 | 150 | 139 | 164 | 144 | 138 | 151 | 136 | 156 | 136 | 163 | 132 | 138 | 146 | 150 | 132 | 139 | 168 | 141 | 147.330000 | NaN | NaN | NaN |
| 7 | 13/10/2023 | 152 | 139 | 137 | 162 | 160 | 158 | 158 | 145 | 140 | 159 | 147 | 139 | 152 | 132 | 132 | 149 | 137 | 152 | 168 | 145 | 144 | 152 | 144 | 164 | 150 | 141 | 154 | 150 | 139 | 165 | 144 | 138 | 151 | 136 | 156 | 136 | 163 | 132 | 139 | 148 | 150 | 132 | 139 | 169 | 143 | 147.600000 | NaN | NaN | NaN |
| 8 | 15/10/2023 | 152 | 139 | 137 | 163 | 161 | 158 | 158 | 145 | 141 | 159 | 147 | 139 | 152 | 132 | 132 | 149 | 137 | 152 | 168 | 145 | 144 | 152 | 144 | 164 | 150 | 141 | 155 | 150 | 139 | 165 | 144 | 138 | 151 | 137 | 156 | 136 | 163 | 132 | 140 | 148 | 150 | 132 | 139 | 169 | 143 | 147.730000 | NaN | NaN | NaN |
| 9 | 18/10/2023 | 152 | 140 | 137 | 163 | 161 | 158 | 159 | 145 | 141 | 159 | 147 | 139 | 152 | 132 | 132 | 149 | 137 | 153 | 168 | 146 | 144 | 152 | 144 | 165 | 150 | 141 | 155 | 150 | 140 | 165 | 144 | 138 | 151 | 137 | 156 | 136 | 163 | 132 | 140 | 148 | 150 | 132 | 139 | 169 | 143 | 147.870000 | NaN | NaN | NaN |
| 10 | 20/10/2023 | 152 | 140 | 137 | 164 | 161 | 158 | 159 | 145 | 141 | 159 | 147 | 139 | 152 | 132 | 132 | 150 | 137 | 153 | 168 | 146 | 145 | 152 | 144 | 166 | 150 | 142 | 155 | 150 | 140 | 165 | 144 | 138 | 151 | 137 | 156 | 136 | 164 | 132 | 140 | 148 | 150 | 132 | 139 | 169 | 143 | 148.000000 | NaN | NaN | NaN |
| 11 | 22/10/2023 | 152 | 140 | 137 | 164 | 161 | 158 | 159 | 145 | 141 | 160 | 147 | 139 | 153 | 133 | 132 | 150 | 137 | 153 | 169 | 146 | 145 | 152 | 144 | 166 | 150 | 142 | 155 | 150 | 140 | 165 | 144 | 138 | 151 | 137 | 157 | 136 | 164 | 132 | 140 | 149 | 150 | 132 | 139 | 169 | 143 | 148.130000 | NaN | NaN | NaN |
| 12 | 25/10/2023 | 152 | 140 | 137 | 165 | 161 | 159 | 159 | 145 | 141 | 160 | 147 | 139 | 154 | 133 | 132 | 150 | 137 | 153 | 169 | 146 | 145 | 152 | 144 | 166 | 151 | 142 | 155 | 150 | 140 | 165 | 145 | 138 | 151 | 137 | 157 | 136 | 164 | 132 | 140 | 149 | 151 | 132 | 139 | 169 | 143 | 148.270000 | NaN | NaN | NaN |
| 13 | 27/10/2023 | 152 | 140 | 137 | 165 | 161 | 159 | 160 | 145 | 141 | 161 | 147 | 139 | 154 | 134 | 132 | 150 | 137 | 153 | 169 | 146 | 146 | 152 | 144 | 166 | 151 | 143 | 155 | 150 | 140 | 165 | 145 | 138 | 151 | 137 | 157 | 136 | 165 | 132 | 140 | 149 | 151 | 132 | 139 | 169 | 143 | 148.400000 | NaN | NaN | NaN |
| 14 | 29/10/2023 | 152 | 140 | 137 | 165 | 162 | 159 | 161 | 145 | 141 | 161 | 147 | 139 | 154 | 134 | 133 | 150 | 137 | 153 | 169 | 146 | 147 | 152 | 144 | 166 | 151 | 143 | 155 | 150 | 140 | 165 | 145 | 139 | 151 | 137 | 157 | 136 | 165 | 132 | 140 | 149 | 151 | 132 | 139 | 169 | 144 | 148.530000 | NaN | NaN | NaN |
| 15 | 1/11/2023 | 153 | 140 | 138 | 165 | 162 | 159 | 161 | 145 | 141 | 161 | 147 | 139 | 154 | 134 | 134 | 151 | 137 | 153 | 169 | 146 | 147 | 152 | 145 | 166 | 151 | 143 | 155 | 151 | 140 | 165 | 145 | 139 | 151 | 137 | 157 | 136 | 165 | 132 | 140 | 149 | 151 | 132 | 139 | 169 | 144 | 148.670000 | NaN | NaN | NaN |
| 16 | 3/11/2023 | 153 | 141 | 138 | 165 | 162 | 159 | 162 | 145 | 142 | 161 | 147 | 139 | 155 | 134 | 134 | 151 | 137 | 153 | 169 | 146 | 147 | 153 | 145 | 166 | 151 | 143 | 155 | 151 | 140 | 165 | 145 | 139 | 151 | 137 | 157 | 136 | 165 | 133 | 140 | 149 | 151 | 132 | 139 | 169 | 144 | 148.800000 | NaN | NaN | NaN |
| 17 | 5/11/2023 | 154 | 141 | 138 | 165 | 162 | 159 | 162 | 145 | 142 | 161 | 147 | 139 | 156 | 134 | 134 | 152 | 137 | 154 | 169 | 146 | 147 | 153 | 146 | 166 | 152 | 143 | 155 | 151 | 140 | 165 | 145 | 139 | 151 | 137 | 157 | 136 | 165 | 133 | 140 | 149 | 151 | 132 | 139 | 169 | 144 | 148.933333 | NaN | NaN | NaN |
| 18 | 8/11/2023 | 154 | 141 | 138 | 165 | 162 | 159 | 163 | 145 | 142 | 161 | 147 | 139 | 156 | 134 | 134 | 152 | 137 | 154 | 169 | 147 | 147 | 153 | 147 | 166 | 152 | 143 | 156 | 151 | 140 | 165 | 146 | 139 | 152 | 137 | 157 | 136 | 165 | 133 | 140 | 149 | 151 | 132 | 139 | 169 | 144 | 149.070000 | NaN | NaN | NaN |
| 19 | 10/11/2023 | 155 | 141 | 138 | 166 | 162 | 159 | 163 | 145 | 142 | 162 | 147 | 139 | 157 | 135 | 134 | 152 | 137 | 154 | 169 | 147 | 147 | 153 | 147 | 166 | 152 | 143 | 156 | 151 | 140 | 165 | 146 | 139 | 152 | 137 | 157 | 136 | 165 | 133 | 140 | 149 | 151 | 132 | 139 | 170 | 144 | 149.200000 | NaN | NaN | NaN |
| 20 | 12/11/2023 | 155 | 142 | 138 | 167 | 162 | 159 | 163 | 145 | 142 | 163 | 147 | 139 | 157 | 135 | 135 | 152 | 137 | 154 | 169 | 147 | 147 | 153 | 147 | 166 | 152 | 143 | 157 | 151 | 140 | 165 | 147 | 139 | 152 | 137 | 157 | 136 | 165 | 133 | 140 | 149 | 151 | 132 | 139 | 170 | 144 | 149.330000 | NaN | NaN | NaN |
| 21 | 15/11/2023 | 155 | 143 | 139 | 167 | 162 | 159 | 163 | 145 | 142 | 163 | 147 | 140 | 157 | 135 | 135 | 153 | 137 | 154 | 169 | 147 | 147 | 153 | 147 | 166 | 152 | 143 | 157 | 151 | 140 | 166 | 147 | 139 | 152 | 137 | 157 | 136 | 166 | 133 | 140 | 149 | 151 | 132 | 139 | 170 | 144 | 149.466667 | NaN | NaN | NaN |
| 22 | 17/11/2023 | 155 | 143 | 139 | 167 | 162 | 159 | 163 | 145 | 142 | 163 | 147 | 140 | 157 | 135 | 135 | 154 | 137 | 154 | 169 | 148 | 147 | 153 | 147 | 166 | 153 | 144 | 157 | 151 | 140 | 166 | 147 | 139 | 152 | 137 | 157 | 137 | 166 | 133 | 140 | 149 | 152 | 132 | 139 | 170 | 144 | 149.600000 | NaN | NaN | NaN |
| 23 | 19/11/2023 | 156 | 143 | 140 | 167 | 162 | 159 | 163 | 145 | 142 | 163 | 147 | 140 | 157 | 135 | 135 | 154 | 137 | 154 | 170 | 149 | 147 | 153 | 147 | 166 | 153 | 145 | 157 | 151 | 140 | 166 | 147 | 139 | 152 | 138 | 157 | 137 | 166 | 133 | 140 | 149 | 152 | 132 | 139 | 170 | 144 | 149.733333 | NaN | NaN | NaN |
| 24 | 22/11/2023 | 156 | 143 | 140 | 167 | 162 | 159 | 163 | 145 | 142 | 163 | 147 | 140 | 157 | 135 | 136 | 154 | 137 | 155 | 170 | 150 | 147 | 153 | 148 | 166 | 153 | 145 | 157 | 151 | 140 | 166 | 147 | 139 | 152 | 138 | 157 | 137 | 167 | 133 | 141 | 149 | 152 | 132 | 139 | 170 | 144 | 149.866667 | NaN | NaN | NaN |
| 25 | 24/11/2023 | 156 | 143 | 140 | 167 | 163 | 159 | 163 | 145 | 142 | 163 | 147 | 140 | 157 | 135 | 136 | 154 | 137 | 156 | 170 | 150 | 147 | 154 | 148 | 166 | 153 | 145 | 157 | 151 | 140 | 166 | 147 | 139 | 152 | 139 | 157 | 137 | 167 | 133 | 141 | 149 | 153 | 132 | 139 | 170 | 145 | 150.000000 | NaN | NaN | NaN |
| 26 | 26/11/2023 | 156 | 143 | 140 | 168 | 163 | 160 | 163 | 145 | 142 | 163 | 147 | 140 | 157 | 135 | 137 | 154 | 137 | 156 | 170 | 150 | 147 | 154 | 149 | 166 | 154 | 145 | 157 | 151 | 140 | 166 | 147 | 139 | 152 | 139 | 157 | 138 | 167 | 133 | 141 | 149 | 153 | 132 | 139 | 170 | 145 | 150.133333 | NaN | NaN | NaN |
| 27 | 29/11/2023 | 156 | 143 | 140 | 168 | 163 | 160 | 163 | 145 | 143 | 163 | 147 | 140 | 157 | 135 | 137 | 154 | 137 | 156 | 170 | 150 | 147 | 155 | 149 | 167 | 154 | 145 | 157 | 151 | 140 | 166 | 147 | 140 | 152 | 139 | 157 | 138 | 167 | 134 | 142 | 149 | 153 | 132 | 139 | 170 | 145 | 150.266667 | NaN | NaN | NaN |
| 28 | 1/12/2023 | 156 | 143 | 140 | 168 | 164 | 160 | 163 | 145 | 143 | 164 | 147 | 140 | 157 | 136 | 137 | 154 | 137 | 156 | 170 | 150 | 148 | 155 | 149 | 167 | 154 | 145 | 158 | 151 | 140 | 166 | 147 | 141 | 152 | 139 | 157 | 138 | 167 | 134 | 142 | 149 | 153 | 132 | 139 | 170 | 145 | 150.400000 | NaN | NaN | NaN |
| 29 | 3/12/2023 | 156 | 143 | 140 | 168 | 164 | 160 | 163 | 145 | 143 | 164 | 147 | 141 | 157 | 137 | 137 | 155 | 137 | 156 | 170 | 150 | 149 | 155 | 149 | 167 | 154 | 145 | 158 | 151 | 141 | 166 | 147 | 142 | 152 | 139 | 157 | 138 | 167 | 134 | 142 | 149 | 153 | 132 | 139 | 170 | 145 | 150.533333 | NaN | NaN | NaN |
| 30 | 6/12/2023 | 156 | 143 | 140 | 168 | 164 | 160 | 163 | 145 | 143 | 164 | 147 | 141 | 157 | 137 | 137 | 155 | 137 | 157 | 171 | 151 | 149 | 155 | 149 | 167 | 154 | 145 | 158 | 151 | 142 | 166 | 147 | 142 | 152 | 139 | 157 | 138 | 167 | 134 | 142 | 149 | 154 | 133 | 139 | 170 | 145 | 150.666667 | NaN | NaN | NaN |
| 31 | 8/12/2023 | 156 | 143 | 140 | 168 | 164 | 160 | 163 | 145 | 143 | 164 | 148 | 141 | 157 | 137 | 138 | 156 | 138 | 157 | 171 | 151 | 149 | 155 | 149 | 167 | 154 | 145 | 158 | 151 | 142 | 166 | 147 | 142 | 152 | 139 | 157 | 138 | 167 | 134 | 142 | 149 | 154 | 134 | 140 | 170 | 145 | 150.800000 | NaN | NaN | NaN |
| 32 | 10/12/2023 | 156 | 143 | 140 | 168 | 164 | 160 | 163 | 145 | 144 | 165 | 149 | 141 | 157 | 137 | 138 | 156 | 139 | 157 | 171 | 151 | 149 | 155 | 149 | 167 | 154 | 145 | 158 | 151 | 142 | 166 | 147 | 142 | 152 | 139 | 157 | 138 | 167 | 134 | 142 | 149 | 155 | 134 | 140 | 171 | 145 | 150.933333 | NaN | NaN | NaN |
| 33 | 13/12/2023 | 156 | 143 | 141 | 168 | 164 | 160 | 164 | 145 | 144 | 165 | 150 | 141 | 157 | 137 | 138 | 156 | 139 | 157 | 171 | 152 | 149 | 155 | 149 | 167 | 154 | 145 | 158 | 152 | 142 | 166 | 147 | 142 | 152 | 139 | 157 | 138 | 167 | 134 | 142 | 149 | 155 | 134 | 140 | 172 | 145 | 151.066667 | NaN | NaN | NaN |
| 34 | 15/12/2023 | 157 | 143 | 141 | 168 | 165 | 160 | 164 | 145 | 144 | 166 | 151 | 141 | 157 | 137 | 138 | 156 | 139 | 157 | 171 | 153 | 149 | 155 | 149 | 167 | 154 | 145 | 158 | 152 | 142 | 166 | 147 | 142 | 152 | 139 | 157 | 138 | 167 | 134 | 142 | 150 | 155 | 134 | 140 | 172 | 145 | 151.200000 | NaN | NaN | NaN |
| 35 | 17/12/2023 | 157 | 143 | 142 | 168 | 165 | 160 | 165 | 145 | 144 | 166 | 151 | 141 | 157 | 137 | 138 | 156 | 139 | 158 | 171 | 154 | 149 | 155 | 149 | 167 | 154 | 145 | 158 | 152 | 142 | 166 | 148 | 142 | 153 | 139 | 157 | 138 | 167 | 134 | 142 | 150 | 155 | 134 | 140 | 172 | 145 | 151.333333 | NaN | NaN | NaN |
| 36 | 20/12/2023 | 157 | 143 | 142 | 168 | 166 | 160 | 165 | 145 | 144 | 166 | 151 | 141 | 157 | 137 | 139 | 157 | 139 | 158 | 171 | 154 | 150 | 156 | 149 | 167 | 154 | 145 | 158 | 152 | 142 | 166 | 148 | 143 | 153 | 139 | 157 | 138 | 167 | 134 | 142 | 150 | 155 | 134 | 140 | 172 | 145 | 151.466667 | NaN | NaN | NaN |
| 37 | 22/12/2023 | 157 | 144 | 142 | 168 | 166 | 160 | 165 | 145 | 144 | 166 | 151 | 142 | 157 | 138 | 139 | 158 | 139 | 158 | 171 | 154 | 150 | 156 | 149 | 167 | 154 | 145 | 158 | 152 | 142 | 166 | 148 | 143 | 153 | 140 | 157 | 138 | 167 | 135 | 142 | 150 | 155 | 134 | 140 | 172 | 145 | 151.600000 | NaN | NaN | NaN |
| 38 | 24/12/2023 | 158 | 145 | 142 | 168 | 167 | 160 | 165 | 145 | 144 | 166 | 151 | 142 | 157 | 138 | 139 | 158 | 139 | 158 | 171 | 154 | 150 | 156 | 149 | 168 | 154 | 145 | 158 | 152 | 142 | 166 | 148 | 143 | 153 | 140 | 157 | 138 | 167 | 135 | 142 | 151 | 155 | 134 | 141 | 172 | 145 | 151.733333 | NaN | NaN | NaN |
| 39 | 27/12/2023 | 158 | 145 | 142 | 168 | 167 | 160 | 165 | 146 | 144 | 166 | 151 | 142 | 157 | 138 | 139 | 159 | 139 | 158 | 171 | 154 | 150 | 156 | 150 | 168 | 154 | 145 | 158 | 152 | 142 | 166 | 148 | 143 | 153 | 141 | 157 | 139 | 167 | 135 | 143 | 151 | 155 | 134 | 141 | 172 | 145 | 151.866667 | NaN | NaN | NaN |
| 40 | 29/12/2023 | 158 | 145 | 142 | 168 | 167 | 160 | 165 | 146 | 144 | 166 | 151 | 142 | 157 | 138 | 139 | 160 | 139 | 158 | 171 | 155 | 150 | 157 | 150 | 168 | 154 | 145 | 158 | 152 | 142 | 166 | 148 | 143 | 153 | 141 | 158 | 139 | 168 | 135 | 144 | 151 | 155 | 134 | 141 | 172 | 145 | 152.000000 | NaN | NaN | NaN |
| 41 | 31/12/2023 | 158 | 145 | 142 | 168 | 167 | 160 | 165 | 146 | 144 | 166 | 151 | 142 | 158 | 139 | 139 | 160 | 139 | 158 | 171 | 155 | 150 | 157 | 151 | 168 | 155 | 145 | 158 | 152 | 142 | 166 | 148 | 143 | 153 | 142 | 158 | 139 | 168 | 135 | 144 | 151 | 155 | 134 | 141 | 173 | 145 | 152.133333 | NaN | NaN | NaN |
| 42 | 3/1/2024 | 158 | 145 | 142 | 168 | 167 | 160 | 165 | 146 | 145 | 166 | 151 | 142 | 158 | 140 | 139 | 160 | 139 | 158 | 172 | 156 | 150 | 157 | 151 | 168 | 155 | 145 | 158 | 152 | 143 | 166 | 148 | 143 | 153 | 142 | 158 | 139 | 168 | 135 | 144 | 152 | 155 | 134 | 141 | 173 | 145 | 152.266667 | NaN | NaN | NaN |
| 43 | 5/1/2024 | 158 | 145 | 142 | 168 | 167 | 160 | 165 | 146 | 146 | 166 | 151 | 142 | 158 | 140 | 139 | 161 | 139 | 158 | 172 | 156 | 150 | 157 | 151 | 168 | 155 | 145 | 158 | 152 | 144 | 166 | 149 | 143 | 154 | 142 | 158 | 139 | 168 | 135 | 144 | 152 | 155 | 135 | 141 | 173 | 145 | 152.400000 | NaN | NaN | NaN |
| 44 | 7/1/2024 | 158 | 145 | 143 | 169 | 167 | 160 | 165 | 146 | 146 | 166 | 151 | 142 | 158 | 140 | 140 | 161 | 139 | 159 | 172 | 156 | 150 | 157 | 151 | 168 | 155 | 145 | 158 | 152 | 144 | 166 | 149 | 143 | 154 | 142 | 158 | 140 | 168 | 135 | 144 | 152 | 155 | 135 | 141 | 173 | 146 | 152.533333 | NaN | NaN | NaN |
| 45 | 10/1/2024 | 158 | 145 | 143 | 169 | 167 | 160 | 165 | 146 | 146 | 167 | 151 | 143 | 158 | 140 | 140 | 161 | 139 | 160 | 173 | 156 | 150 | 157 | 151 | 168 | 155 | 145 | 158 | 152 | 145 | 166 | 149 | 143 | 154 | 142 | 158 | 140 | 168 | 135 | 144 | 152 | 155 | 135 | 142 | 173 | 146 | 152.666667 | NaN | NaN | NaN |
| 46 | 12/1/2024 | 158 | 145 | 143 | 169 | 167 | 160 | 165 | 146 | 146 | 168 | 152 | 143 | 158 | 140 | 140 | 161 | 139 | 160 | 173 | 157 | 150 | 157 | 151 | 168 | 155 | 145 | 159 | 152 | 145 | 166 | 149 | 143 | 154 | 142 | 158 | 140 | 168 | 135 | 145 | 152 | 155 | 135 | 143 | 173 | 146 | 152.800000 | NaN | NaN | NaN |
| 47 | 14/1/2024 | 158 | 146 | 143 | 169 | 167 | 160 | 165 | 147 | 146 | 168 | 152 | 143 | 158 | 140 | 140 | 161 | 139 | 160 | 174 | 158 | 150 | 157 | 151 | 169 | 155 | 145 | 159 | 152 | 145 | 166 | 149 | 143 | 154 | 142 | 158 | 140 | 168 | 135 | 145 | 152 | 155 | 136 | 143 | 173 | 146 | 152.933333 | NaN | NaN | NaN |
| 48 | 17/1/2024 | 158 | 146 | 143 | 169 | 167 | 160 | 165 | 147 | 146 | 168 | 152 | 143 | 158 | 141 | 140 | 161 | 139 | 160 | 175 | 158 | 151 | 157 | 151 | 169 | 155 | 145 | 159 | 152 | 145 | 166 | 149 | 143 | 154 | 142 | 158 | 141 | 168 | 135 | 145 | 152 | 155 | 136 | 144 | 174 | 146 | 153.066667 | NaN | NaN | NaN |
| 49 | 19/1/2024 | 158 | 146 | 143 | 169 | 167 | 160 | 165 | 148 | 146 | 168 | 152 | 143 | 158 | 141 | 141 | 161 | 139 | 160 | 175 | 159 | 151 | 157 | 151 | 170 | 155 | 145 | 159 | 152 | 145 | 166 | 149 | 143 | 154 | 142 | 158 | 141 | 168 | 135 | 145 | 152 | 155 | 136 | 145 | 175 | 146 | 153.200000 | NaN | NaN | NaN |
| 50 | 21/1/2024 | 158 | 146 | 143 | 169 | 167 | 160 | 165 | 148 | 146 | 168 | 153 | 143 | 158 | 141 | 141 | 161 | 139 | 160 | 175 | 160 | 151 | 158 | 152 | 170 | 155 | 146 | 159 | 152 | 145 | 166 | 150 | 143 | 154 | 142 | 158 | 141 | 168 | 135 | 145 | 152 | 155 | 136 | 145 | 175 | 146 | 153.333333 | NaN | NaN | NaN |
| 51 | 24/1/2024 | 158 | 146 | 143 | 169 | 167 | 160 | 166 | 148 | 146 | 168 | 153 | 143 | 158 | 141 | 141 | 161 | 139 | 160 | 175 | 160 | 151 | 158 | 152 | 170 | 155 | 146 | 160 | 152 | 145 | 167 | 150 | 143 | 154 | 142 | 158 | 142 | 168 | 135 | 146 | 152 | 155 | 136 | 145 | 175 | 147 | 153.466667 | NaN | NaN | NaN |
| 52 | 26/1/2024 | 158 | 146 | 143 | 169 | 167 | 160 | 166 | 149 | 146 | 168 | 153 | 143 | 158 | 141 | 141 | 161 | 139 | 160 | 176 | 160 | 151 | 159 | 152 | 170 | 155 | 146 | 161 | 152 | 145 | 167 | 151 | 143 | 154 | 142 | 159 | 142 | 168 | 135 | 146 | 152 | 155 | 136 | 145 | 175 | 147 | 153.600000 | NaN | NaN | NaN |
| 53 | 28/1/2024 | 158 | 146 | 144 | 169 | 167 | 160 | 166 | 149 | 146 | 168 | 153 | 143 | 158 | 141 | 141 | 161 | 139 | 160 | 176 | 160 | 151 | 159 | 153 | 170 | 156 | 146 | 161 | 152 | 146 | 167 | 151 | 143 | 154 | 142 | 159 | 143 | 168 | 135 | 146 | 152 | 156 | 136 | 146 | 175 | 147 | 153.755556 | NaN | NaN | NaN |
| 54 | 31/1/2024 | 158 | 146 | 144 | 169 | 167 | 160 | 166 | 149 | 147 | 168 | 154 | 143 | 158 | 141 | 142 | 161 | 139 | 160 | 176 | 160 | 151 | 159 | 153 | 170 | 156 | 146 | 161 | 152 | 146 | 167 | 151 | 143 | 154 | 142 | 160 | 143 | 168 | 136 | 146 | 152 | 157 | 136 | 146 | 175 | 147 | 153.888889 | NaN | NaN | NaN |
| 55 | 2/2/2024 | 159 | 146 | 144 | 169 | 167 | 160 | 166 | 149 | 147 | 168 | 154 | 143 | 158 | 141 | 143 | 161 | 139 | 160 | 176 | 160 | 151 | 159 | 153 | 170 | 156 | 146 | 161 | 152 | 147 | 167 | 152 | 144 | 154 | 143 | 160 | 143 | 168 | 136 | 146 | 152 | 157 | 136 | 146 | 175 | 147 | 154.022222 | NaN | NaN | NaN |
| 56 | 4/2/2024 | 159 | 146 | 144 | 169 | 167 | 160 | 166 | 149 | 148 | 168 | 154 | 143 | 158 | 141 | 144 | 161 | 139 | 160 | 176 | 160 | 152 | 159 | 153 | 170 | 156 | 146 | 161 | 152 | 148 | 167 | 152 | 144 | 155 | 143 | 160 | 143 | 168 | 136 | 147 | 152 | 157 | 136 | 146 | 175 | 147 | 154.155556 | NaN | NaN | NaN |
| 57 | 7/2/2024 | 159 | 146 | 144 | 169 | 167 | 160 | 166 | 149 | 148 | 168 | 154 | 143 | 158 | 141 | 144 | 161 | 140 | 160 | 176 | 160 | 153 | 159 | 153 | 171 | 157 | 146 | 161 | 152 | 148 | 167 | 152 | 144 | 155 | 143 | 160 | 143 | 168 | 136 | 148 | 152 | 157 | 137 | 146 | 175 | 147 | 154.288889 | NaN | NaN | NaN |
| 58 | 11/2/2024 | 159 | 146 | 144 | 169 | 167 | 160 | 167 | 149 | 148 | 168 | 154 | 143 | 158 | 141 | 144 | 161 | 140 | 161 | 176 | 160 | 153 | 159 | 153 | 171 | 157 | 146 | 161 | 152 | 148 | 167 | 153 | 144 | 156 | 143 | 161 | 143 | 168 | 136 | 148 | 152 | 158 | 137 | 146 | 175 | 147 | 154.422222 | NaN | NaN | NaN |
| 59 | 14/2/2024 | 159 | 146 | 144 | 169 | 167 | 160 | 167 | 150 | 149 | 168 | 155 | 144 | 158 | 141 | 144 | 161 | 140 | 161 | 176 | 160 | 153 | 159 | 153 | 171 | 157 | 146 | 161 | 152 | 148 | 167 | 153 | 144 | 156 | 143 | 161 | 143 | 168 | 136 | 148 | 153 | 158 | 137 | 146 | 176 | 147 | 154.555556 | NaN | NaN | NaN |
| 60 | 16/2/2024 | 159 | 146 | 144 | 169 | 167 | 161 | 167 | 150 | 149 | 169 | 155 | 144 | 158 | 141 | 144 | 162 | 140 | 161 | 176 | 161 | 153 | 159 | 153 | 171 | 157 | 146 | 161 | 152 | 148 | 167 | 153 | 144 | 156 | 143 | 161 | 143 | 168 | 136 | 148 | 154 | 158 | 138 | 146 | 176 | 147 | 154.688889 | NaN | NaN | NaN |
| 61 | 18/2/2024 | 159 | 146 | 144 | 169 | 168 | 161 | 167 | 150 | 149 | 169 | 155 | 144 | 158 | 141 | 144 | 162 | 140 | 161 | 177 | 162 | 154 | 159 | 153 | 172 | 157 | 146 | 161 | 152 | 148 | 167 | 153 | 144 | 156 | 143 | 161 | 143 | 168 | 136 | 148 | 155 | 158 | 138 | 146 | 176 | 147 | 154.822222 | NaN | NaN | NaN |
| 62 | 21/2/2024 | 159 | 147 | 144 | 169 | 168 | 161 | 167 | 151 | 149 | 169 | 155 | 144 | 158 | 142 | 144 | 162 | 140 | 161 | 178 | 162 | 154 | 159 | 153 | 173 | 157 | 146 | 161 | 152 | 148 | 167 | 153 | 144 | 156 | 143 | 161 | 143 | 168 | 136 | 148 | 155 | 158 | 139 | 146 | 176 | 147 | 154.955556 | NaN | NaN | NaN |
| 63 | 23/2/2024 | 159 | 147 | 144 | 170 | 168 | 161 | 167 | 151 | 149 | 169 | 155 | 144 | 158 | 142 | 144 | 162 | 141 | 161 | 179 | 162 | 154 | 159 | 153 | 173 | 157 | 146 | 162 | 153 | 148 | 167 | 153 | 144 | 156 | 143 | 161 | 144 | 168 | 136 | 148 | 155 | 158 | 139 | 146 | 176 | 147 | 155.088889 | NaN | NaN | NaN |
2. Hàm định dạng lại đúng, kiểm tra kiểu Ngày/Tháng/Năm - dd/mm/yyyy
# Chuyển đổi cột ngày tháng thành định dạng 'yyyy/mm/dd'
df['Date'] = pd.to_datetime(df['Date'], format='%d/%m/%Y')
# Hiển thị DataFrame đã chuyển đổi
print(f"Date range of gold from - {df.loc[:,'Date'][0]} to {df.loc[:,'Date'][len(df)-1]}")
# Tạo DatetimeIndex từ '9/28/2023' đến ngày cuối cùng trong DataFrame df
daterange = pd.date_range(start='9/24/2023', end=df.loc[:, 'Date'].iloc[-1], freq='D')
formatted_date = daterange.strftime('%d/%m/%Y')
# Thay thế ngày cuối cùng bằng ngày trong DataFrame df
print(formatted_date)
Date range of gold from - 2023-09-24 00:00:00 to 2024-02-23 00:00:00
Index(['24/09/2023', '25/09/2023', '26/09/2023', '27/09/2023', '28/09/2023',
'29/09/2023', '30/09/2023', '01/10/2023', '02/10/2023', '03/10/2023',
...
'14/02/2024', '15/02/2024', '16/02/2024', '17/02/2024', '18/02/2024',
'19/02/2024', '20/02/2024', '21/02/2024', '22/02/2024', '23/02/2024'],
dtype='object', length=153)
3. Các Hàm thủ tục Kiểm tra Dữ liệu --> Validate and Cleaning Data
3.1. Hàm chống trùng lặp dữ liệudf = df.drop_duplicates()
df.shape
(64, 50)
3. Các Hàm thủ tục Kiểm tra Dữ liệu --> Validate and Cleaning Data
3.2. Hàm matplotlib.pyplot vẽ biểu đồ kiểm tra tính logic của dữ liệuimport pandas as pd
import matplotlib.pyplot as plt
# Đọc dữ liệu từ file csv
data = pd.read_csv(r"C:\Python311\workspaces\m6B45.csv")
# Thiết lập kích thước biểu đồ
plt.figure(figsize=(10, 6))
# Vẽ các đường line từ S01 đến S45
for column in data.columns[1:46]:
plt.plot(data['Date'], data[column], label=column)
# Thiết lập tiêu đề và các trục
plt.title('Biểu đồ thống kê số lần')
plt.xlabel('Ngày')
plt.ylabel('Số lần')
# Xoay đứng trục ngày tháng
plt.xticks(rotation='vertical')
# Hiển thị grid
plt.grid(True)
# Hiển thị chú thích
plt.legend(bbox_to_anchor=(1.05, 1), loc='upper left')
# Hiển thị biểu đồ
plt.show()
3. Các Hàm thủ tục Kiểm tra Dữ liệu --> Validate and Cleaning Data
3.3. Hàm describe() tính toán các chỉ số max, min, 25% tối thiểu, 50% trung bình, 75% hiệu suất để kiểm tra tính hợp lệ của dữ liệuround(df.describe(),2)
| Date | S01 | S02 | S03 | S04 | S05 | S06 | S07 | S08 | S09 | S10 | S11 | S12 | S13 | S14 | S15 | S16 | S17 | S18 | S19 | S20 | S21 | S22 | S23 | S24 | S25 | S26 | S27 | S28 | S29 | S30 | S31 | S32 | S33 | S34 | S35 | S36 | S37 | S38 | S39 | S40 | S41 | S42 | S43 | S44 | S45 | ST | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| count | 64 | 64.00 | 64.00 | 64.00 | 64.00 | 64.00 | 64.00 | 64.00 | 64.00 | 64.00 | 64.00 | 64.00 | 64.00 | 64.00 | 64.00 | 64.00 | 64.0 | 64.00 | 64.00 | 64.00 | 64.00 | 64.00 | 64.00 | 64.00 | 64.00 | 64.00 | 64.00 | 64.00 | 64.00 | 64.00 | 64.00 | 64.00 | 64.00 | 64.00 | 64.00 | 64.00 | 64.00 | 64.00 | 64.00 | 64.00 | 64.00 | 64.00 | 64.00 | 64.00 | 64.00 | 64.00 | 64.00 |
| mean | 2023-12-09 03:00:00 | 155.75 | 143.02 | 140.48 | 166.73 | 164.08 | 159.47 | 163.08 | 146.14 | 143.73 | 164.08 | 149.55 | 141.00 | 156.14 | 136.84 | 137.38 | 155.5 | 138.08 | 156.44 | 171.36 | 152.27 | 148.44 | 155.05 | 148.56 | 167.27 | 153.44 | 144.16 | 157.48 | 151.09 | 142.34 | 165.70 | 147.64 | 140.98 | 152.55 | 139.44 | 157.64 | 138.58 | 166.30 | 133.91 | 142.34 | 149.88 | 153.48 | 133.84 | 141.08 | 171.50 | 144.62 | 150.85 |
| min | 2023-09-24 00:00:00 | 151.00 | 137.00 | 136.00 | 160.00 | 159.00 | 158.00 | 157.00 | 143.00 | 140.00 | 158.00 | 145.00 | 138.00 | 151.00 | 132.00 | 132.00 | 146.0 | 136.00 | 151.00 | 167.00 | 145.00 | 143.00 | 150.00 | 143.00 | 162.00 | 150.00 | 141.00 | 152.00 | 148.00 | 139.00 | 161.00 | 144.00 | 137.00 | 149.00 | 136.00 | 156.00 | 135.00 | 162.00 | 132.00 | 136.00 | 144.00 | 149.00 | 132.00 | 137.00 | 168.00 | 140.00 | 146.40 |
| 25% | 2023-11-02 12:00:00 | 153.00 | 140.75 | 138.00 | 165.00 | 162.00 | 159.00 | 161.75 | 145.00 | 141.75 | 161.00 | 147.00 | 139.00 | 154.75 | 134.00 | 134.00 | 151.0 | 137.00 | 153.00 | 169.00 | 146.00 | 147.00 | 152.75 | 145.00 | 166.00 | 151.00 | 143.00 | 155.00 | 151.00 | 140.00 | 165.00 | 145.00 | 139.00 | 151.00 | 137.00 | 157.00 | 136.00 | 165.00 | 132.75 | 140.00 | 149.00 | 151.00 | 132.00 | 139.00 | 169.00 | 144.00 | 148.77 |
| 50% | 2023-12-09 00:00:00 | 156.00 | 143.00 | 140.00 | 168.00 | 164.00 | 160.00 | 163.00 | 145.00 | 143.50 | 164.50 | 148.50 | 141.00 | 157.00 | 137.00 | 138.00 | 156.0 | 138.50 | 157.00 | 171.00 | 151.00 | 149.00 | 155.00 | 149.00 | 167.00 | 154.00 | 145.00 | 158.00 | 151.00 | 142.00 | 166.00 | 147.00 | 142.00 | 152.00 | 139.00 | 157.00 | 138.00 | 167.00 | 134.00 | 142.00 | 149.00 | 154.50 | 134.00 | 140.00 | 170.50 | 145.00 | 150.87 |
| 75% | 2024-01-14 18:00:00 | 158.00 | 146.00 | 143.00 | 169.00 | 167.00 | 160.00 | 165.00 | 147.00 | 146.00 | 168.00 | 152.00 | 143.00 | 158.00 | 140.25 | 140.00 | 161.0 | 139.00 | 160.00 | 174.25 | 158.00 | 150.25 | 157.00 | 151.00 | 169.00 | 155.00 | 145.00 | 159.00 | 152.00 | 145.00 | 166.00 | 149.00 | 143.00 | 154.00 | 142.00 | 158.00 | 140.25 | 168.00 | 135.00 | 145.00 | 152.00 | 155.00 | 136.00 | 143.25 | 173.25 | 146.00 | 152.97 |
| max | 2024-02-23 00:00:00 | 159.00 | 147.00 | 144.00 | 170.00 | 168.00 | 161.00 | 167.00 | 151.00 | 149.00 | 169.00 | 155.00 | 144.00 | 158.00 | 142.00 | 144.00 | 162.0 | 141.00 | 161.00 | 179.00 | 162.00 | 154.00 | 159.00 | 153.00 | 173.00 | 157.00 | 146.00 | 162.00 | 153.00 | 148.00 | 167.00 | 153.00 | 144.00 | 156.00 | 143.00 | 161.00 | 144.00 | 168.00 | 136.00 | 148.00 | 155.00 | 158.00 | 139.00 | 146.00 | 176.00 | 147.00 | 155.09 |
| std | NaN | 2.77 | 2.75 | 2.67 | 2.69 | 2.97 | 0.87 | 3.03 | 1.88 | 2.76 | 3.63 | 3.13 | 1.81 | 2.33 | 3.41 | 4.05 | 5.2 | 1.26 | 3.30 | 3.18 | 5.89 | 3.03 | 2.78 | 3.29 | 2.52 | 2.29 | 1.75 | 2.42 | 1.20 | 3.04 | 1.09 | 2.82 | 2.43 | 1.85 | 2.53 | 1.47 | 2.65 | 1.88 | 1.44 | 3.27 | 2.55 | 2.72 | 2.08 | 2.86 | 2.64 | 1.94 | 2.51 |
3. Các Hàm thủ tục Kiểm tra Dữ liệu --> Validate and Cleaning Data
3.4. Hàm columns kiểm tra xác định tên Trường dữ liệudf.columns
Index(['Date', 'S01', 'S02', 'S03', 'S04', 'S05', 'S06', 'S07', 'S08', 'S09',
'S10', 'S11', 'S12', 'S13', 'S14', 'S15', 'S16', 'S17', 'S18', 'S19',
'S20', 'S21', 'S22', 'S23', 'S24', 'S25', 'S26', 'S27', 'S28', 'S29',
'S30', 'S31', 'S32', 'S33', 'S34', 'S35', 'S36', 'S37', 'S38', 'S39',
'S40', 'S41', 'S42', 'S43', 'S44', 'S45', 'ST', 'Link', 'Type', 'BD'],
dtype='object')
3. Các Hàm thủ tục Kiểm tra Dữ liệu --> Validate and Cleaning Data
3.5. Hàm info() kiểm tra phân loại Kiểu dữ liệu non-null, dtypes: datetime64[ns](1), float64(1), int64(55), object(3)df.info()
<class 'pandas.core.frame.DataFrame'> RangeIndex: 64 entries, 0 to 63 Data columns (total 50 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 Date 64 non-null datetime64[ns] 1 S01 64 non-null int64 2 S02 64 non-null int64 3 S03 64 non-null int64 4 S04 64 non-null int64 5 S05 64 non-null int64 6 S06 64 non-null int64 7 S07 64 non-null int64 8 S08 64 non-null int64 9 S09 64 non-null int64 10 S10 64 non-null int64 11 S11 64 non-null int64 12 S12 64 non-null int64 13 S13 64 non-null int64 14 S14 64 non-null int64 15 S15 64 non-null int64 16 S16 64 non-null int64 17 S17 64 non-null int64 18 S18 64 non-null int64 19 S19 64 non-null int64 20 S20 64 non-null int64 21 S21 64 non-null int64 22 S22 64 non-null int64 23 S23 64 non-null int64 24 S24 64 non-null int64 25 S25 64 non-null int64 26 S26 64 non-null int64 27 S27 64 non-null int64 28 S28 64 non-null int64 29 S29 64 non-null int64 30 S30 64 non-null int64 31 S31 64 non-null int64 32 S32 64 non-null int64 33 S33 64 non-null int64 34 S34 64 non-null int64 35 S35 64 non-null int64 36 S36 64 non-null int64 37 S37 64 non-null int64 38 S38 64 non-null int64 39 S39 64 non-null int64 40 S40 64 non-null int64 41 S41 64 non-null int64 42 S42 64 non-null int64 43 S43 64 non-null int64 44 S44 64 non-null int64 45 S45 64 non-null int64 46 ST 64 non-null float64 47 Link 1 non-null object 48 Type 1 non-null object 49 BD 1 non-null object dtypes: datetime64[ns](1), float64(1), int64(45), object(3) memory usage: 25.1+ KB
3. Các Hàm thủ tục Kiểm tra Dữ liệu --> Validate and Cleaning Data
3.6. Hàm .isnull().sum() kiểm tra các giá trị supervisor nhập vào thiếu/đủ/thừa giá trịdf.isnull().sum()
Date 0 S01 0 S02 0 S03 0 S04 0 S05 0 S06 0 S07 0 S08 0 S09 0 S10 0 S11 0 S12 0 S13 0 S14 0 S15 0 S16 0 S17 0 S18 0 S19 0 S20 0 S21 0 S22 0 S23 0 S24 0 S25 0 S26 0 S27 0 S28 0 S29 0 S30 0 S31 0 S32 0 S33 0 S34 0 S35 0 S36 0 S37 0 S38 0 S39 0 S40 0 S41 0 S42 0 S43 0 S44 0 S45 0 ST 0 Link 63 Type 63 BD 63 dtype: int64
3. Các Hàm thủ tục Kiểm tra Dữ liệu --> Validate and Cleaning Data
3.7. Hàm .isnull() kiểm tra các giá trị supervisor nhập vào sai/đúng kiểu giá trịdf.isnull()
| Date | S01 | S02 | S03 | S04 | S05 | S06 | S07 | S08 | S09 | S10 | S11 | S12 | S13 | S14 | S15 | S16 | S17 | S18 | S19 | S20 | S21 | S22 | S23 | S24 | S25 | S26 | S27 | S28 | S29 | S30 | S31 | S32 | S33 | S34 | S35 | S36 | S37 | S38 | S39 | S40 | S41 | S42 | S43 | S44 | S45 | ST | Link | Type | BD | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False |
| 1 | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | True | True | True |
| 2 | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | True | True | True |
| 3 | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | True | True | True |
| 4 | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | True | True | True |
| 5 | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | True | True | True |
| 6 | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | True | True | True |
| 7 | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | True | True | True |
| 8 | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | True | True | True |
| 9 | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | True | True | True |
| 10 | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | True | True | True |
| 11 | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | True | True | True |
| 12 | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | True | True | True |
| 13 | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | True | True | True |
| 14 | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | True | True | True |
| 15 | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | True | True | True |
| 16 | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | True | True | True |
| 17 | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | True | True | True |
| 18 | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | True | True | True |
| 19 | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | True | True | True |
| 20 | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | True | True | True |
| 21 | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | True | True | True |
| 22 | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | True | True | True |
| 23 | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | True | True | True |
| 24 | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | True | True | True |
| 25 | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | True | True | True |
| 26 | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | True | True | True |
| 27 | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | True | True | True |
| 28 | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | True | True | True |
| 29 | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | True | True | True |
| 30 | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | True | True | True |
| 31 | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | True | True | True |
| 32 | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | True | True | True |
| 33 | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | True | True | True |
| 34 | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | True | True | True |
| 35 | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | True | True | True |
| 36 | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | True | True | True |
| 37 | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | True | True | True |
| 38 | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | True | True | True |
| 39 | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | True | True | True |
| 40 | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | True | True | True |
| 41 | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | True | True | True |
| 42 | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | True | True | True |
| 43 | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | True | True | True |
| 44 | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | True | True | True |
| 45 | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | True | True | True |
| 46 | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | True | True | True |
| 47 | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | True | True | True |
| 48 | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | True | True | True |
| 49 | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | True | True | True |
| 50 | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | True | True | True |
| 51 | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | True | True | True |
| 52 | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | True | True | True |
| 53 | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | True | True | True |
| 54 | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | True | True | True |
| 55 | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | True | True | True |
| 56 | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | True | True | True |
| 57 | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | True | True | True |
| 58 | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | True | True | True |
| 59 | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | True | True | True |
| 60 | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | True | True | True |
| 61 | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | True | True | True |
| 62 | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | True | True | True |
| 63 | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | True | True | True |
3. Các Hàm thủ tục Kiểm tra Dữ liệu --> Validate and Cleaning Data
3.8. Hàm .duplicated().sum() kiểm tra các giá trị, tổng supervisor nhập vào bị trùng lặp giá trịdf.duplicated().sum()
0
3. Các Hàm thủ tục Kiểm tra Dữ liệu --> Validate and Cleaning Data
3.9. Hàm describe().T Bảng mở rộng tính toán các chỉ số: - max, - min, - 25% tối thiểu, - 50% trung bình, - 75% hiệu suất để kiểm tra tính hợp lệ của dữ liệu#EDA --> Explorer Data Analysis:
import pandas as pd
# Đặt display.max_rows thành một số lớn hơn số hàng trong DataFrame
pd.set_option("display.max_rows", df.shape[0] + 1)
pd.set_option("display.max_columns", 60)
# Hiển thị mô tả thống kê với tất cả các hàng giá trị
#df.describe()
round(df.describe().T,2)
# Trong hàm df.describe().T, cột "std" đại diện cho độ lệch chuẩn (standard deviation) của dữ liệu trong các cột tương ứng.
# Độ lệch chuẩn là một số đo mô tả mức độ phân tán của dữ liệu xung quanh giá trị trung bình.
# Công thức tính độ lệch chuẩn là căn bậc hai của phương sai (variance), và được tính bằng cách lấy căn bậc hai của trung bình của
# bình phương của độ lệch của mỗi giá trị dữ liệu so với giá trị trung bình. Công thức chính xác như sau:
# std = sqrt(mean((x - x.mean())**2))
# Trong trường hợp của bạn, giá trị "std" là 1.8959 cho một cột và 2.03572 cho cột khác.
# Khi so sánh giá trị độ lệch chuẩn giữa các cột, giá trị lớn hơn có nghĩa là dữ liệu trong cột đó có mức độ phân tán lớn hơn so với cột khác.
| count | mean | min | 25% | 50% | 75% | max | std | |
|---|---|---|---|---|---|---|---|---|
| Date | 64 | 2023-12-09 03:00:00 | 2023-09-24 00:00:00 | 2023-11-02 12:00:00 | 2023-12-09 00:00:00 | 2024-01-14 18:00:00 | 2024-02-23 00:00:00 | NaN |
| S01 | 64.0 | 155.75 | 151.0 | 153.0 | 156.0 | 158.0 | 159.0 | 2.766007 |
| S02 | 64.0 | 143.015625 | 137.0 | 140.75 | 143.0 | 146.0 | 147.0 | 2.751578 |
| S03 | 64.0 | 140.484375 | 136.0 | 138.0 | 140.0 | 143.0 | 144.0 | 2.66662 |
| S04 | 64.0 | 166.734375 | 160.0 | 165.0 | 168.0 | 169.0 | 170.0 | 2.691799 |
| S05 | 64.0 | 164.078125 | 159.0 | 162.0 | 164.0 | 167.0 | 168.0 | 2.972384 |
| S06 | 64.0 | 159.46875 | 158.0 | 159.0 | 160.0 | 160.0 | 161.0 | 0.872303 |
| S07 | 64.0 | 163.078125 | 157.0 | 161.75 | 163.0 | 165.0 | 167.0 | 3.025315 |
| S08 | 64.0 | 146.140625 | 143.0 | 145.0 | 145.0 | 147.0 | 151.0 | 1.8845 |
| S09 | 64.0 | 143.734375 | 140.0 | 141.75 | 143.5 | 146.0 | 149.0 | 2.761655 |
| S10 | 64.0 | 164.078125 | 158.0 | 161.0 | 164.5 | 168.0 | 169.0 | 3.626642 |
| S11 | 64.0 | 149.546875 | 145.0 | 147.0 | 148.5 | 152.0 | 155.0 | 3.126587 |
| S12 | 64.0 | 141.0 | 138.0 | 139.0 | 141.0 | 143.0 | 144.0 | 1.80827 |
| S13 | 64.0 | 156.140625 | 151.0 | 154.75 | 157.0 | 158.0 | 158.0 | 2.329025 |
| S14 | 64.0 | 136.84375 | 132.0 | 134.0 | 137.0 | 140.25 | 142.0 | 3.409691 |
| S15 | 64.0 | 137.375 | 132.0 | 134.0 | 138.0 | 140.0 | 144.0 | 4.053217 |
| S16 | 64.0 | 155.5 | 146.0 | 151.0 | 156.0 | 161.0 | 162.0 | 5.203784 |
| S17 | 64.0 | 138.078125 | 136.0 | 137.0 | 138.5 | 139.0 | 141.0 | 1.263714 |
| S18 | 64.0 | 156.4375 | 151.0 | 153.0 | 157.0 | 160.0 | 161.0 | 3.29923 |
| S19 | 64.0 | 171.359375 | 167.0 | 169.0 | 171.0 | 174.25 | 179.0 | 3.184123 |
| S20 | 64.0 | 152.265625 | 145.0 | 146.0 | 151.0 | 158.0 | 162.0 | 5.885797 |
| S21 | 64.0 | 148.4375 | 143.0 | 147.0 | 149.0 | 150.25 | 154.0 | 3.033543 |
| S22 | 64.0 | 155.046875 | 150.0 | 152.75 | 155.0 | 157.0 | 159.0 | 2.779915 |
| S23 | 64.0 | 148.5625 | 143.0 | 145.0 | 149.0 | 151.0 | 153.0 | 3.289594 |
| S24 | 64.0 | 167.265625 | 162.0 | 166.0 | 167.0 | 169.0 | 173.0 | 2.521288 |
| S25 | 64.0 | 153.4375 | 150.0 | 151.0 | 154.0 | 155.0 | 157.0 | 2.294749 |
| S26 | 64.0 | 144.15625 | 141.0 | 143.0 | 145.0 | 145.0 | 146.0 | 1.747731 |
| S27 | 64.0 | 157.484375 | 152.0 | 155.0 | 158.0 | 159.0 | 162.0 | 2.423379 |
| S28 | 64.0 | 151.09375 | 148.0 | 151.0 | 151.0 | 152.0 | 153.0 | 1.204736 |
| S29 | 64.0 | 142.34375 | 139.0 | 140.0 | 142.0 | 145.0 | 148.0 | 3.035341 |
| S30 | 64.0 | 165.703125 | 161.0 | 165.0 | 166.0 | 166.0 | 167.0 | 1.0937 |
| S31 | 64.0 | 147.640625 | 144.0 | 145.0 | 147.0 | 149.0 | 153.0 | 2.819249 |
| S32 | 64.0 | 140.984375 | 137.0 | 139.0 | 142.0 | 143.0 | 144.0 | 2.426652 |
| S33 | 64.0 | 152.546875 | 149.0 | 151.0 | 152.0 | 154.0 | 156.0 | 1.851037 |
| S34 | 64.0 | 139.4375 | 136.0 | 137.0 | 139.0 | 142.0 | 143.0 | 2.525269 |
| S35 | 64.0 | 157.640625 | 156.0 | 157.0 | 157.0 | 158.0 | 161.0 | 1.473223 |
| S36 | 64.0 | 138.578125 | 135.0 | 136.0 | 138.0 | 140.25 | 144.0 | 2.647579 |
| S37 | 64.0 | 166.296875 | 162.0 | 165.0 | 167.0 | 168.0 | 168.0 | 1.88292 |
| S38 | 64.0 | 133.90625 | 132.0 | 132.75 | 134.0 | 135.0 | 136.0 | 1.444406 |
| S39 | 64.0 | 142.34375 | 136.0 | 140.0 | 142.0 | 145.0 | 148.0 | 3.267049 |
| S40 | 64.0 | 149.875 | 144.0 | 149.0 | 149.0 | 152.0 | 155.0 | 2.554175 |
| S41 | 64.0 | 153.484375 | 149.0 | 151.0 | 154.5 | 155.0 | 158.0 | 2.719665 |
| S42 | 64.0 | 133.84375 | 132.0 | 132.0 | 134.0 | 136.0 | 139.0 | 2.07952 |
| S43 | 64.0 | 141.078125 | 137.0 | 139.0 | 140.0 | 143.25 | 146.0 | 2.86359 |
| S44 | 64.0 | 171.5 | 168.0 | 169.0 | 170.5 | 173.25 | 176.0 | 2.636737 |
| S45 | 64.0 | 144.625 | 140.0 | 144.0 | 145.0 | 146.0 | 147.0 | 1.939563 |
| ST | 64.0 | 150.853819 | 146.4 | 148.7675 | 150.866667 | 152.966667 | 155.088889 | 2.514648 |
3. Các Hàm thủ tục Kiểm tra Dữ liệu --> Vaidate and Cleaning Data
3.10. Hàm describe(include="object") kiểm tra tính hợp lệ của dữ liệu dạng Object gồm: string, blob, clob, vchardf.describe(include="object")
| Link | Type | BD | |
|---|---|---|---|
| count | 1 | 1 | 1 |
| unique | 1 | 1 | 1 |
| top | https://vietlott/vn/vi/choi/mega-6-45/thong-ke... | M6B45 | 18/07/2016 |
| freq | 1 | 1 | 1 |
4. Các Hàm thủ tục Thống kê và Phân tích Dữ liệu --> Analytics/Statistic Data
4.1. Hàm sns.kdeplot Biểu diễn mật độ và độ thay đổi dữ liệu sốimport warnings
warnings.filterwarnings('ignore')
for i in df.select_dtypes(include="number").columns:
plt.figure(figsize=(15,6))
sns.kdeplot(data=df,x=i)
plt.grid()
plt.show()
#Liet ke cac so theo mật độ = số lần xuất hiện thay đổi
# lệch phải : 08 --> hầu như không có lần nào thay đổi sau 35 lần gần nhất thống kê.
4. Các Hàm thủ tục Thống kê và Phân tích Dữ liệu --> Analytics/Statistic Data
4.2. Hàm sns.kdeplot mở rộng so sánh với Giá trị thực để xác định độ thay đổi dữ liệu số#Để vẽ đồ thị mật độ (density plot) kèm theo độ lệch chuẩn (standard deviation),
#bạn có thể sử dụng thư viện seaborn và matplotlib trong Python. Dưới đây là một ví dụ về cách thực hiện điều này:
# Trong đoạn mã trên, chúng ta sử dụng vòng lặp để duyệt qua từng cột là kiểu dữ liệu số trong dataframe (df).
#Sau đó, chúng ta vẽ đồ thị mật độ bằng hàm kdeplot từ thư viện seaborn.
#Để xác định độ lệch chuẩn, chúng ta sử dụng hàm mean() để tính giá trị trung bình và hàm std()
#để tính độ lệch chuẩn của cột tương ứng. Cuối cùng, chúng ta sử dụng hàm axvline() từ matplotlib
#để vẽ các đường dọc đại diện cho giá trị trung bình và độ lệch chuẩn.
# Lưu ý rằng đoạn mã trên giả định rằng dữ liệu trong dataframe của bạn đã được đọc và xử lý đúng cách trước đó.
import seaborn as sns
import matplotlib.pyplot as plt
# Vẽ đồ thị mật độ kèm theo độ lệch chuẩn
for col in df.select_dtypes(include="number").columns:
plt.figure(figsize=(15, 6))
sns.kdeplot(data=df, x=col)
mean = df[col].mean()
std = df[col].std()
plt.axvline(x=mean, color='r', linestyle='--', label='Mean')
plt.axvline(x=mean + std, color='g', linestyle='--', label='Mean + Std')
plt.axvline(x=mean - std, color='g', linestyle='--', label='Mean - Std')
plt.legend()
plt.show
# Các tình huống trên biểu đồ và các legend được sử dụng để biểu thị giá trị trung bình và độ lệch chuẩn của dữ liệu trong cột tương ứng.
# Legend "Mean" (giá trị trung bình): Đường dọc đại diện cho giá trị trung bình của dữ liệu trong cột.
# Nó giúp xác định giá trị trung bình của phân phối dữ liệu trên biểu đồ.
# Legend "Mean + Std" (giá trị trung bình + độ lệch chuẩn): Đường dọc đại diện cho giá trị trung bình cộng với độ lệch chuẩn của dữ liệu.
# Nó cho thấy phạm vi mà khoảng 68% dữ liệu nằm trong đó (khi giả định dữ liệu tuân theo phân phối chuẩn).
# Legend "Mean - Std" (giá trị trung bình - độ lệch chuẩn): Đường dọc đại diện cho giá trị trung bình trừ đi độ lệch chuẩn của dữ liệu.
# Nó cũng cho thấy phạm vi mà khoảng 68% dữ liệu nằm trong đó (khi giả định dữ liệu tuân theo phân phối chuẩn).
NHẬN XÉT:
df = pd.read_csv(r"C:\Python311\workspaces\m6B45.csv")
pd.set_option("display.max_rows",df.shape[0]+1)
pd.set_option("display.max_columns",60)
df
| Date | S01 | S02 | S03 | S04 | S05 | S06 | S07 | S08 | S09 | S10 | S11 | S12 | S13 | S14 | S15 | S16 | S17 | S18 | S19 | S20 | S21 | S22 | S23 | S24 | S25 | S26 | S27 | S28 | S29 | S30 | S31 | S32 | S33 | S34 | S35 | S36 | S37 | S38 | S39 | S40 | S41 | S42 | S43 | S44 | S45 | ST | Link | Type | BD | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 24/9/2023 | 151 | 137 | 136 | 160 | 159 | 158 | 157 | 143 | 140 | 158 | 145 | 138 | 151 | 132 | 132 | 146 | 136 | 151 | 167 | 145 | 143 | 150 | 143 | 162 | 150 | 141 | 152 | 148 | 139 | 161 | 144 | 137 | 149 | 136 | 156 | 135 | 162 | 132 | 136 | 144 | 149 | 132 | 137 | 168 | 140 | 146.400000 | https://vietlott/vn/vi/choi/mega-6-45/thong-ke... | M6B45 | 18/07/2016 |
| 1 | 27/9/2023 | 151 | 137 | 137 | 161 | 159 | 158 | 157 | 144 | 140 | 158 | 145 | 139 | 151 | 132 | 132 | 146 | 136 | 151 | 167 | 145 | 143 | 151 | 144 | 162 | 150 | 141 | 153 | 148 | 139 | 163 | 144 | 137 | 149 | 136 | 156 | 136 | 163 | 132 | 137 | 144 | 149 | 132 | 137 | 168 | 140 | 146.670000 | NaN | NaN | NaN |
| 2 | 29/9/2023 | 151 | 138 | 137 | 161 | 159 | 158 | 157 | 145 | 140 | 158 | 145 | 139 | 151 | 132 | 132 | 146 | 136 | 151 | 167 | 145 | 143 | 151 | 144 | 163 | 150 | 141 | 154 | 148 | 139 | 164 | 144 | 137 | 149 | 136 | 156 | 136 | 163 | 132 | 137 | 144 | 149 | 132 | 138 | 168 | 140 | 146.800000 | NaN | NaN | NaN |
| 3 | 1/10/2023 | 151 | 139 | 137 | 161 | 159 | 158 | 157 | 145 | 140 | 158 | 146 | 139 | 152 | 132 | 132 | 147 | 136 | 151 | 167 | 145 | 143 | 151 | 144 | 163 | 150 | 141 | 154 | 148 | 139 | 164 | 144 | 137 | 149 | 136 | 156 | 136 | 163 | 132 | 137 | 144 | 150 | 132 | 139 | 168 | 140 | 146.930000 | NaN | NaN | NaN |
| 4 | 4/10/2023 | 151 | 139 | 137 | 161 | 159 | 158 | 158 | 145 | 140 | 158 | 146 | 139 | 152 | 132 | 132 | 147 | 137 | 151 | 167 | 145 | 144 | 151 | 144 | 163 | 150 | 141 | 154 | 148 | 139 | 164 | 144 | 138 | 149 | 136 | 156 | 136 | 163 | 132 | 137 | 145 | 150 | 132 | 139 | 168 | 141 | 147.070000 | NaN | NaN | NaN |
| 5 | 6/10/2023 | 151 | 139 | 137 | 161 | 159 | 158 | 158 | 145 | 140 | 158 | 146 | 139 | 152 | 132 | 132 | 147 | 137 | 152 | 168 | 145 | 144 | 151 | 144 | 164 | 150 | 141 | 154 | 149 | 139 | 164 | 144 | 138 | 150 | 136 | 156 | 136 | 163 | 132 | 137 | 146 | 150 | 132 | 139 | 168 | 141 | 147.200000 | NaN | NaN | NaN |
| 6 | 8/10/2023 | 151 | 139 | 137 | 162 | 159 | 158 | 158 | 145 | 140 | 158 | 146 | 139 | 152 | 132 | 132 | 148 | 137 | 152 | 168 | 145 | 144 | 152 | 144 | 164 | 150 | 141 | 154 | 150 | 139 | 164 | 144 | 138 | 151 | 136 | 156 | 136 | 163 | 132 | 138 | 146 | 150 | 132 | 139 | 168 | 141 | 147.330000 | NaN | NaN | NaN |
| 7 | 13/10/2023 | 152 | 139 | 137 | 162 | 160 | 158 | 158 | 145 | 140 | 159 | 147 | 139 | 152 | 132 | 132 | 149 | 137 | 152 | 168 | 145 | 144 | 152 | 144 | 164 | 150 | 141 | 154 | 150 | 139 | 165 | 144 | 138 | 151 | 136 | 156 | 136 | 163 | 132 | 139 | 148 | 150 | 132 | 139 | 169 | 143 | 147.600000 | NaN | NaN | NaN |
| 8 | 15/10/2023 | 152 | 139 | 137 | 163 | 161 | 158 | 158 | 145 | 141 | 159 | 147 | 139 | 152 | 132 | 132 | 149 | 137 | 152 | 168 | 145 | 144 | 152 | 144 | 164 | 150 | 141 | 155 | 150 | 139 | 165 | 144 | 138 | 151 | 137 | 156 | 136 | 163 | 132 | 140 | 148 | 150 | 132 | 139 | 169 | 143 | 147.730000 | NaN | NaN | NaN |
| 9 | 18/10/2023 | 152 | 140 | 137 | 163 | 161 | 158 | 159 | 145 | 141 | 159 | 147 | 139 | 152 | 132 | 132 | 149 | 137 | 153 | 168 | 146 | 144 | 152 | 144 | 165 | 150 | 141 | 155 | 150 | 140 | 165 | 144 | 138 | 151 | 137 | 156 | 136 | 163 | 132 | 140 | 148 | 150 | 132 | 139 | 169 | 143 | 147.870000 | NaN | NaN | NaN |
| 10 | 20/10/2023 | 152 | 140 | 137 | 164 | 161 | 158 | 159 | 145 | 141 | 159 | 147 | 139 | 152 | 132 | 132 | 150 | 137 | 153 | 168 | 146 | 145 | 152 | 144 | 166 | 150 | 142 | 155 | 150 | 140 | 165 | 144 | 138 | 151 | 137 | 156 | 136 | 164 | 132 | 140 | 148 | 150 | 132 | 139 | 169 | 143 | 148.000000 | NaN | NaN | NaN |
| 11 | 22/10/2023 | 152 | 140 | 137 | 164 | 161 | 158 | 159 | 145 | 141 | 160 | 147 | 139 | 153 | 133 | 132 | 150 | 137 | 153 | 169 | 146 | 145 | 152 | 144 | 166 | 150 | 142 | 155 | 150 | 140 | 165 | 144 | 138 | 151 | 137 | 157 | 136 | 164 | 132 | 140 | 149 | 150 | 132 | 139 | 169 | 143 | 148.130000 | NaN | NaN | NaN |
| 12 | 25/10/2023 | 152 | 140 | 137 | 165 | 161 | 159 | 159 | 145 | 141 | 160 | 147 | 139 | 154 | 133 | 132 | 150 | 137 | 153 | 169 | 146 | 145 | 152 | 144 | 166 | 151 | 142 | 155 | 150 | 140 | 165 | 145 | 138 | 151 | 137 | 157 | 136 | 164 | 132 | 140 | 149 | 151 | 132 | 139 | 169 | 143 | 148.270000 | NaN | NaN | NaN |
| 13 | 27/10/2023 | 152 | 140 | 137 | 165 | 161 | 159 | 160 | 145 | 141 | 161 | 147 | 139 | 154 | 134 | 132 | 150 | 137 | 153 | 169 | 146 | 146 | 152 | 144 | 166 | 151 | 143 | 155 | 150 | 140 | 165 | 145 | 138 | 151 | 137 | 157 | 136 | 165 | 132 | 140 | 149 | 151 | 132 | 139 | 169 | 143 | 148.400000 | NaN | NaN | NaN |
| 14 | 29/10/2023 | 152 | 140 | 137 | 165 | 162 | 159 | 161 | 145 | 141 | 161 | 147 | 139 | 154 | 134 | 133 | 150 | 137 | 153 | 169 | 146 | 147 | 152 | 144 | 166 | 151 | 143 | 155 | 150 | 140 | 165 | 145 | 139 | 151 | 137 | 157 | 136 | 165 | 132 | 140 | 149 | 151 | 132 | 139 | 169 | 144 | 148.530000 | NaN | NaN | NaN |
| 15 | 1/11/2023 | 153 | 140 | 138 | 165 | 162 | 159 | 161 | 145 | 141 | 161 | 147 | 139 | 154 | 134 | 134 | 151 | 137 | 153 | 169 | 146 | 147 | 152 | 145 | 166 | 151 | 143 | 155 | 151 | 140 | 165 | 145 | 139 | 151 | 137 | 157 | 136 | 165 | 132 | 140 | 149 | 151 | 132 | 139 | 169 | 144 | 148.670000 | NaN | NaN | NaN |
| 16 | 3/11/2023 | 153 | 141 | 138 | 165 | 162 | 159 | 162 | 145 | 142 | 161 | 147 | 139 | 155 | 134 | 134 | 151 | 137 | 153 | 169 | 146 | 147 | 153 | 145 | 166 | 151 | 143 | 155 | 151 | 140 | 165 | 145 | 139 | 151 | 137 | 157 | 136 | 165 | 133 | 140 | 149 | 151 | 132 | 139 | 169 | 144 | 148.800000 | NaN | NaN | NaN |
| 17 | 5/11/2023 | 154 | 141 | 138 | 165 | 162 | 159 | 162 | 145 | 142 | 161 | 147 | 139 | 156 | 134 | 134 | 152 | 137 | 154 | 169 | 146 | 147 | 153 | 146 | 166 | 152 | 143 | 155 | 151 | 140 | 165 | 145 | 139 | 151 | 137 | 157 | 136 | 165 | 133 | 140 | 149 | 151 | 132 | 139 | 169 | 144 | 148.933333 | NaN | NaN | NaN |
| 18 | 8/11/2023 | 154 | 141 | 138 | 165 | 162 | 159 | 163 | 145 | 142 | 161 | 147 | 139 | 156 | 134 | 134 | 152 | 137 | 154 | 169 | 147 | 147 | 153 | 147 | 166 | 152 | 143 | 156 | 151 | 140 | 165 | 146 | 139 | 152 | 137 | 157 | 136 | 165 | 133 | 140 | 149 | 151 | 132 | 139 | 169 | 144 | 149.070000 | NaN | NaN | NaN |
| 19 | 10/11/2023 | 155 | 141 | 138 | 166 | 162 | 159 | 163 | 145 | 142 | 162 | 147 | 139 | 157 | 135 | 134 | 152 | 137 | 154 | 169 | 147 | 147 | 153 | 147 | 166 | 152 | 143 | 156 | 151 | 140 | 165 | 146 | 139 | 152 | 137 | 157 | 136 | 165 | 133 | 140 | 149 | 151 | 132 | 139 | 170 | 144 | 149.200000 | NaN | NaN | NaN |
| 20 | 12/11/2023 | 155 | 142 | 138 | 167 | 162 | 159 | 163 | 145 | 142 | 163 | 147 | 139 | 157 | 135 | 135 | 152 | 137 | 154 | 169 | 147 | 147 | 153 | 147 | 166 | 152 | 143 | 157 | 151 | 140 | 165 | 147 | 139 | 152 | 137 | 157 | 136 | 165 | 133 | 140 | 149 | 151 | 132 | 139 | 170 | 144 | 149.330000 | NaN | NaN | NaN |
| 21 | 15/11/2023 | 155 | 143 | 139 | 167 | 162 | 159 | 163 | 145 | 142 | 163 | 147 | 140 | 157 | 135 | 135 | 153 | 137 | 154 | 169 | 147 | 147 | 153 | 147 | 166 | 152 | 143 | 157 | 151 | 140 | 166 | 147 | 139 | 152 | 137 | 157 | 136 | 166 | 133 | 140 | 149 | 151 | 132 | 139 | 170 | 144 | 149.466667 | NaN | NaN | NaN |
| 22 | 17/11/2023 | 155 | 143 | 139 | 167 | 162 | 159 | 163 | 145 | 142 | 163 | 147 | 140 | 157 | 135 | 135 | 154 | 137 | 154 | 169 | 148 | 147 | 153 | 147 | 166 | 153 | 144 | 157 | 151 | 140 | 166 | 147 | 139 | 152 | 137 | 157 | 137 | 166 | 133 | 140 | 149 | 152 | 132 | 139 | 170 | 144 | 149.600000 | NaN | NaN | NaN |
| 23 | 19/11/2023 | 156 | 143 | 140 | 167 | 162 | 159 | 163 | 145 | 142 | 163 | 147 | 140 | 157 | 135 | 135 | 154 | 137 | 154 | 170 | 149 | 147 | 153 | 147 | 166 | 153 | 145 | 157 | 151 | 140 | 166 | 147 | 139 | 152 | 138 | 157 | 137 | 166 | 133 | 140 | 149 | 152 | 132 | 139 | 170 | 144 | 149.733333 | NaN | NaN | NaN |
| 24 | 22/11/2023 | 156 | 143 | 140 | 167 | 162 | 159 | 163 | 145 | 142 | 163 | 147 | 140 | 157 | 135 | 136 | 154 | 137 | 155 | 170 | 150 | 147 | 153 | 148 | 166 | 153 | 145 | 157 | 151 | 140 | 166 | 147 | 139 | 152 | 138 | 157 | 137 | 167 | 133 | 141 | 149 | 152 | 132 | 139 | 170 | 144 | 149.866667 | NaN | NaN | NaN |
| 25 | 24/11/2023 | 156 | 143 | 140 | 167 | 163 | 159 | 163 | 145 | 142 | 163 | 147 | 140 | 157 | 135 | 136 | 154 | 137 | 156 | 170 | 150 | 147 | 154 | 148 | 166 | 153 | 145 | 157 | 151 | 140 | 166 | 147 | 139 | 152 | 139 | 157 | 137 | 167 | 133 | 141 | 149 | 153 | 132 | 139 | 170 | 145 | 150.000000 | NaN | NaN | NaN |
| 26 | 26/11/2023 | 156 | 143 | 140 | 168 | 163 | 160 | 163 | 145 | 142 | 163 | 147 | 140 | 157 | 135 | 137 | 154 | 137 | 156 | 170 | 150 | 147 | 154 | 149 | 166 | 154 | 145 | 157 | 151 | 140 | 166 | 147 | 139 | 152 | 139 | 157 | 138 | 167 | 133 | 141 | 149 | 153 | 132 | 139 | 170 | 145 | 150.133333 | NaN | NaN | NaN |
| 27 | 29/11/2023 | 156 | 143 | 140 | 168 | 163 | 160 | 163 | 145 | 143 | 163 | 147 | 140 | 157 | 135 | 137 | 154 | 137 | 156 | 170 | 150 | 147 | 155 | 149 | 167 | 154 | 145 | 157 | 151 | 140 | 166 | 147 | 140 | 152 | 139 | 157 | 138 | 167 | 134 | 142 | 149 | 153 | 132 | 139 | 170 | 145 | 150.266667 | NaN | NaN | NaN |
| 28 | 1/12/2023 | 156 | 143 | 140 | 168 | 164 | 160 | 163 | 145 | 143 | 164 | 147 | 140 | 157 | 136 | 137 | 154 | 137 | 156 | 170 | 150 | 148 | 155 | 149 | 167 | 154 | 145 | 158 | 151 | 140 | 166 | 147 | 141 | 152 | 139 | 157 | 138 | 167 | 134 | 142 | 149 | 153 | 132 | 139 | 170 | 145 | 150.400000 | NaN | NaN | NaN |
| 29 | 3/12/2023 | 156 | 143 | 140 | 168 | 164 | 160 | 163 | 145 | 143 | 164 | 147 | 141 | 157 | 137 | 137 | 155 | 137 | 156 | 170 | 150 | 149 | 155 | 149 | 167 | 154 | 145 | 158 | 151 | 141 | 166 | 147 | 142 | 152 | 139 | 157 | 138 | 167 | 134 | 142 | 149 | 153 | 132 | 139 | 170 | 145 | 150.533333 | NaN | NaN | NaN |
| 30 | 6/12/2023 | 156 | 143 | 140 | 168 | 164 | 160 | 163 | 145 | 143 | 164 | 147 | 141 | 157 | 137 | 137 | 155 | 137 | 157 | 171 | 151 | 149 | 155 | 149 | 167 | 154 | 145 | 158 | 151 | 142 | 166 | 147 | 142 | 152 | 139 | 157 | 138 | 167 | 134 | 142 | 149 | 154 | 133 | 139 | 170 | 145 | 150.666667 | NaN | NaN | NaN |
| 31 | 8/12/2023 | 156 | 143 | 140 | 168 | 164 | 160 | 163 | 145 | 143 | 164 | 148 | 141 | 157 | 137 | 138 | 156 | 138 | 157 | 171 | 151 | 149 | 155 | 149 | 167 | 154 | 145 | 158 | 151 | 142 | 166 | 147 | 142 | 152 | 139 | 157 | 138 | 167 | 134 | 142 | 149 | 154 | 134 | 140 | 170 | 145 | 150.800000 | NaN | NaN | NaN |
| 32 | 10/12/2023 | 156 | 143 | 140 | 168 | 164 | 160 | 163 | 145 | 144 | 165 | 149 | 141 | 157 | 137 | 138 | 156 | 139 | 157 | 171 | 151 | 149 | 155 | 149 | 167 | 154 | 145 | 158 | 151 | 142 | 166 | 147 | 142 | 152 | 139 | 157 | 138 | 167 | 134 | 142 | 149 | 155 | 134 | 140 | 171 | 145 | 150.933333 | NaN | NaN | NaN |
| 33 | 13/12/2023 | 156 | 143 | 141 | 168 | 164 | 160 | 164 | 145 | 144 | 165 | 150 | 141 | 157 | 137 | 138 | 156 | 139 | 157 | 171 | 152 | 149 | 155 | 149 | 167 | 154 | 145 | 158 | 152 | 142 | 166 | 147 | 142 | 152 | 139 | 157 | 138 | 167 | 134 | 142 | 149 | 155 | 134 | 140 | 172 | 145 | 151.066667 | NaN | NaN | NaN |
| 34 | 15/12/2023 | 157 | 143 | 141 | 168 | 165 | 160 | 164 | 145 | 144 | 166 | 151 | 141 | 157 | 137 | 138 | 156 | 139 | 157 | 171 | 153 | 149 | 155 | 149 | 167 | 154 | 145 | 158 | 152 | 142 | 166 | 147 | 142 | 152 | 139 | 157 | 138 | 167 | 134 | 142 | 150 | 155 | 134 | 140 | 172 | 145 | 151.200000 | NaN | NaN | NaN |
| 35 | 17/12/2023 | 157 | 143 | 142 | 168 | 165 | 160 | 165 | 145 | 144 | 166 | 151 | 141 | 157 | 137 | 138 | 156 | 139 | 158 | 171 | 154 | 149 | 155 | 149 | 167 | 154 | 145 | 158 | 152 | 142 | 166 | 148 | 142 | 153 | 139 | 157 | 138 | 167 | 134 | 142 | 150 | 155 | 134 | 140 | 172 | 145 | 151.333333 | NaN | NaN | NaN |
| 36 | 20/12/2023 | 157 | 143 | 142 | 168 | 166 | 160 | 165 | 145 | 144 | 166 | 151 | 141 | 157 | 137 | 139 | 157 | 139 | 158 | 171 | 154 | 150 | 156 | 149 | 167 | 154 | 145 | 158 | 152 | 142 | 166 | 148 | 143 | 153 | 139 | 157 | 138 | 167 | 134 | 142 | 150 | 155 | 134 | 140 | 172 | 145 | 151.466667 | NaN | NaN | NaN |
| 37 | 22/12/2023 | 157 | 144 | 142 | 168 | 166 | 160 | 165 | 145 | 144 | 166 | 151 | 142 | 157 | 138 | 139 | 158 | 139 | 158 | 171 | 154 | 150 | 156 | 149 | 167 | 154 | 145 | 158 | 152 | 142 | 166 | 148 | 143 | 153 | 140 | 157 | 138 | 167 | 135 | 142 | 150 | 155 | 134 | 140 | 172 | 145 | 151.600000 | NaN | NaN | NaN |
| 38 | 24/12/2023 | 158 | 145 | 142 | 168 | 167 | 160 | 165 | 145 | 144 | 166 | 151 | 142 | 157 | 138 | 139 | 158 | 139 | 158 | 171 | 154 | 150 | 156 | 149 | 168 | 154 | 145 | 158 | 152 | 142 | 166 | 148 | 143 | 153 | 140 | 157 | 138 | 167 | 135 | 142 | 151 | 155 | 134 | 141 | 172 | 145 | 151.733333 | NaN | NaN | NaN |
| 39 | 27/12/2023 | 158 | 145 | 142 | 168 | 167 | 160 | 165 | 146 | 144 | 166 | 151 | 142 | 157 | 138 | 139 | 159 | 139 | 158 | 171 | 154 | 150 | 156 | 150 | 168 | 154 | 145 | 158 | 152 | 142 | 166 | 148 | 143 | 153 | 141 | 157 | 139 | 167 | 135 | 143 | 151 | 155 | 134 | 141 | 172 | 145 | 151.866667 | NaN | NaN | NaN |
| 40 | 29/12/2023 | 158 | 145 | 142 | 168 | 167 | 160 | 165 | 146 | 144 | 166 | 151 | 142 | 157 | 138 | 139 | 160 | 139 | 158 | 171 | 155 | 150 | 157 | 150 | 168 | 154 | 145 | 158 | 152 | 142 | 166 | 148 | 143 | 153 | 141 | 158 | 139 | 168 | 135 | 144 | 151 | 155 | 134 | 141 | 172 | 145 | 152.000000 | NaN | NaN | NaN |
| 41 | 31/12/2023 | 158 | 145 | 142 | 168 | 167 | 160 | 165 | 146 | 144 | 166 | 151 | 142 | 158 | 139 | 139 | 160 | 139 | 158 | 171 | 155 | 150 | 157 | 151 | 168 | 155 | 145 | 158 | 152 | 142 | 166 | 148 | 143 | 153 | 142 | 158 | 139 | 168 | 135 | 144 | 151 | 155 | 134 | 141 | 173 | 145 | 152.133333 | NaN | NaN | NaN |
| 42 | 3/1/2024 | 158 | 145 | 142 | 168 | 167 | 160 | 165 | 146 | 145 | 166 | 151 | 142 | 158 | 140 | 139 | 160 | 139 | 158 | 172 | 156 | 150 | 157 | 151 | 168 | 155 | 145 | 158 | 152 | 143 | 166 | 148 | 143 | 153 | 142 | 158 | 139 | 168 | 135 | 144 | 152 | 155 | 134 | 141 | 173 | 145 | 152.266667 | NaN | NaN | NaN |
| 43 | 5/1/2024 | 158 | 145 | 142 | 168 | 167 | 160 | 165 | 146 | 146 | 166 | 151 | 142 | 158 | 140 | 139 | 161 | 139 | 158 | 172 | 156 | 150 | 157 | 151 | 168 | 155 | 145 | 158 | 152 | 144 | 166 | 149 | 143 | 154 | 142 | 158 | 139 | 168 | 135 | 144 | 152 | 155 | 135 | 141 | 173 | 145 | 152.400000 | NaN | NaN | NaN |
| 44 | 7/1/2024 | 158 | 145 | 143 | 169 | 167 | 160 | 165 | 146 | 146 | 166 | 151 | 142 | 158 | 140 | 140 | 161 | 139 | 159 | 172 | 156 | 150 | 157 | 151 | 168 | 155 | 145 | 158 | 152 | 144 | 166 | 149 | 143 | 154 | 142 | 158 | 140 | 168 | 135 | 144 | 152 | 155 | 135 | 141 | 173 | 146 | 152.533333 | NaN | NaN | NaN |
| 45 | 10/1/2024 | 158 | 145 | 143 | 169 | 167 | 160 | 165 | 146 | 146 | 167 | 151 | 143 | 158 | 140 | 140 | 161 | 139 | 160 | 173 | 156 | 150 | 157 | 151 | 168 | 155 | 145 | 158 | 152 | 145 | 166 | 149 | 143 | 154 | 142 | 158 | 140 | 168 | 135 | 144 | 152 | 155 | 135 | 142 | 173 | 146 | 152.666667 | NaN | NaN | NaN |
| 46 | 12/1/2024 | 158 | 145 | 143 | 169 | 167 | 160 | 165 | 146 | 146 | 168 | 152 | 143 | 158 | 140 | 140 | 161 | 139 | 160 | 173 | 157 | 150 | 157 | 151 | 168 | 155 | 145 | 159 | 152 | 145 | 166 | 149 | 143 | 154 | 142 | 158 | 140 | 168 | 135 | 145 | 152 | 155 | 135 | 143 | 173 | 146 | 152.800000 | NaN | NaN | NaN |
| 47 | 14/1/2024 | 158 | 146 | 143 | 169 | 167 | 160 | 165 | 147 | 146 | 168 | 152 | 143 | 158 | 140 | 140 | 161 | 139 | 160 | 174 | 158 | 150 | 157 | 151 | 169 | 155 | 145 | 159 | 152 | 145 | 166 | 149 | 143 | 154 | 142 | 158 | 140 | 168 | 135 | 145 | 152 | 155 | 136 | 143 | 173 | 146 | 152.933333 | NaN | NaN | NaN |
| 48 | 17/1/2024 | 158 | 146 | 143 | 169 | 167 | 160 | 165 | 147 | 146 | 168 | 152 | 143 | 158 | 141 | 140 | 161 | 139 | 160 | 175 | 158 | 151 | 157 | 151 | 169 | 155 | 145 | 159 | 152 | 145 | 166 | 149 | 143 | 154 | 142 | 158 | 141 | 168 | 135 | 145 | 152 | 155 | 136 | 144 | 174 | 146 | 153.066667 | NaN | NaN | NaN |
| 49 | 19/1/2024 | 158 | 146 | 143 | 169 | 167 | 160 | 165 | 148 | 146 | 168 | 152 | 143 | 158 | 141 | 141 | 161 | 139 | 160 | 175 | 159 | 151 | 157 | 151 | 170 | 155 | 145 | 159 | 152 | 145 | 166 | 149 | 143 | 154 | 142 | 158 | 141 | 168 | 135 | 145 | 152 | 155 | 136 | 145 | 175 | 146 | 153.200000 | NaN | NaN | NaN |
| 50 | 21/1/2024 | 158 | 146 | 143 | 169 | 167 | 160 | 165 | 148 | 146 | 168 | 153 | 143 | 158 | 141 | 141 | 161 | 139 | 160 | 175 | 160 | 151 | 158 | 152 | 170 | 155 | 146 | 159 | 152 | 145 | 166 | 150 | 143 | 154 | 142 | 158 | 141 | 168 | 135 | 145 | 152 | 155 | 136 | 145 | 175 | 146 | 153.333333 | NaN | NaN | NaN |
| 51 | 24/1/2024 | 158 | 146 | 143 | 169 | 167 | 160 | 166 | 148 | 146 | 168 | 153 | 143 | 158 | 141 | 141 | 161 | 139 | 160 | 175 | 160 | 151 | 158 | 152 | 170 | 155 | 146 | 160 | 152 | 145 | 167 | 150 | 143 | 154 | 142 | 158 | 142 | 168 | 135 | 146 | 152 | 155 | 136 | 145 | 175 | 147 | 153.466667 | NaN | NaN | NaN |
| 52 | 26/1/2024 | 158 | 146 | 143 | 169 | 167 | 160 | 166 | 149 | 146 | 168 | 153 | 143 | 158 | 141 | 141 | 161 | 139 | 160 | 176 | 160 | 151 | 159 | 152 | 170 | 155 | 146 | 161 | 152 | 145 | 167 | 151 | 143 | 154 | 142 | 159 | 142 | 168 | 135 | 146 | 152 | 155 | 136 | 145 | 175 | 147 | 153.600000 | NaN | NaN | NaN |
| 53 | 28/1/2024 | 158 | 146 | 144 | 169 | 167 | 160 | 166 | 149 | 146 | 168 | 153 | 143 | 158 | 141 | 141 | 161 | 139 | 160 | 176 | 160 | 151 | 159 | 153 | 170 | 156 | 146 | 161 | 152 | 146 | 167 | 151 | 143 | 154 | 142 | 159 | 143 | 168 | 135 | 146 | 152 | 156 | 136 | 146 | 175 | 147 | 153.755556 | NaN | NaN | NaN |
| 54 | 31/1/2024 | 158 | 146 | 144 | 169 | 167 | 160 | 166 | 149 | 147 | 168 | 154 | 143 | 158 | 141 | 142 | 161 | 139 | 160 | 176 | 160 | 151 | 159 | 153 | 170 | 156 | 146 | 161 | 152 | 146 | 167 | 151 | 143 | 154 | 142 | 160 | 143 | 168 | 136 | 146 | 152 | 157 | 136 | 146 | 175 | 147 | 153.888889 | NaN | NaN | NaN |
| 55 | 2/2/2024 | 159 | 146 | 144 | 169 | 167 | 160 | 166 | 149 | 147 | 168 | 154 | 143 | 158 | 141 | 143 | 161 | 139 | 160 | 176 | 160 | 151 | 159 | 153 | 170 | 156 | 146 | 161 | 152 | 147 | 167 | 152 | 144 | 154 | 143 | 160 | 143 | 168 | 136 | 146 | 152 | 157 | 136 | 146 | 175 | 147 | 154.022222 | NaN | NaN | NaN |
| 56 | 4/2/2024 | 159 | 146 | 144 | 169 | 167 | 160 | 166 | 149 | 148 | 168 | 154 | 143 | 158 | 141 | 144 | 161 | 139 | 160 | 176 | 160 | 152 | 159 | 153 | 170 | 156 | 146 | 161 | 152 | 148 | 167 | 152 | 144 | 155 | 143 | 160 | 143 | 168 | 136 | 147 | 152 | 157 | 136 | 146 | 175 | 147 | 154.155556 | NaN | NaN | NaN |
| 57 | 7/2/2024 | 159 | 146 | 144 | 169 | 167 | 160 | 166 | 149 | 148 | 168 | 154 | 143 | 158 | 141 | 144 | 161 | 140 | 160 | 176 | 160 | 153 | 159 | 153 | 171 | 157 | 146 | 161 | 152 | 148 | 167 | 152 | 144 | 155 | 143 | 160 | 143 | 168 | 136 | 148 | 152 | 157 | 137 | 146 | 175 | 147 | 154.288889 | NaN | NaN | NaN |
| 58 | 11/2/2024 | 159 | 146 | 144 | 169 | 167 | 160 | 167 | 149 | 148 | 168 | 154 | 143 | 158 | 141 | 144 | 161 | 140 | 161 | 176 | 160 | 153 | 159 | 153 | 171 | 157 | 146 | 161 | 152 | 148 | 167 | 153 | 144 | 156 | 143 | 161 | 143 | 168 | 136 | 148 | 152 | 158 | 137 | 146 | 175 | 147 | 154.422222 | NaN | NaN | NaN |
4. Các Hàm thủ tục Thống kê và Phân tích Dữ liệu --> Analytics/Statistic Data
4.3. Hàm sns.boxplot mở rộng so sánh với Giá trị thực để xác định độ thay đổi / tổng từng giá trị của dữ liệu số Chú thích: - Hàm sns.boxplot trong thư viện Seaborn được sử dụng để vẽ biểu đồ hộp (box plot). Biểu đồ hộp cho phép chúng ta hiển thị phân phối của một biến dữ liệu và các thông số thống kê liên quan. - Thông qua biểu đồ hộp, chúng ta có thể trực quan hóa các thông số như giá trị trung vị (median), phạm vi (range), tứ phân vị (quartiles), và các giá trị ngoại lệ (outliers). Điều này giúp chúng ta có cái nhìn tổng quan về sự phân bố và biến động của dữ liệu. - Tuy nhiên, trong phân tích giá trị về diễn biến tổng khối lượng so với giá trị diễn biến thay đổi như nến (volume trong chứng khoán), biểu đồ hộp có thể không phù hợp. - Thông thường, biểu đồ hộp được sử dụng để phân tích các biến dữ liệu số (numerical variables) và không có sự phụ thuộc giữa các mẫu dữ liệu. - Trong trường hợp giá trị diễn biến tổng khối lượng và giá trị diễn biến thay đổi như nến trong chứng khoán, có thể sử dụng các biểu đồ khác như biểu đồ đường (line plot) hoặc biểu đồ thanh (bar plot) để biểu diễn sự biến đổi của dữ liệu theo thời gian hoặc các nhóm khác nhau.for i in df.select_dtypes(include="number").columns:
plt.figure(figsize=(15,6))
sns.boxplot(data=df,x=i)
plt.grid()
plt.show()
# poe AI: tôi nhìn thấy có biểu đồ dạng Box nhưng lại có:
# 1. 02 ký hiệu o tròn không liền hoặc không nằm trên đường line, hoặc
# 2. dạng chỉ có 1 , 2, 3 chữ o tròn, hoặc
# 3. có 1 o tròn nằm bên trái bên phải lại là box có line hoặc
# 4. có 2 o nằm bên phải còn bên trái lại có 1 box có line,
# 5. dạng có 2 line và ở giữa có 1 box,
# 6. dạng có 2 line ở 2 bên và 1 box bị chia đôi,
# 7. dạng có 2 o tròn bên trái chia đôi bằng 1 line dọc và 4 o tròn bên phải,
# 8. dạng bên trái có line và 1 box rất to bên phải hoặc ngược lại,
# 9. dạng có 1 box duy nhất to và có 1 đường line dọc chia đôi ở giữa,
# 10. dạng có 1 box duy nhất to và có 1 đường line dọc chia đôi lệch bên trái,
# 11. dạng có 1 box duy nhất to và có 1 đường line dọc chia đôi lệch bên phải, thì những biểu đồ trên thể hiện số liệu gì?
#Dựa vào mô tả chi tiết về các biểu đồ box plot trong câu hỏi của bạn, dưới đây là một giải thích về từng trường hợp:
#1. Hai ký hiệu o tròn không liền hoặc không nằm trên đường line: Đây là trường hợp khi có hai outliers không liên tục trong dữ liệu.
#2. Số lượng o tròn khác nhau (1, 2, 3): Số lượng o tròn biểu thị số lượng outliers tương ứng trong dữ liệu.
# Ví dụ: 1 o tròn có thể chỉ ra một outlier duy nhất, trong khi 2 o tròn có thể chỉ ra hai outliers.
#3. Box với line ở một bên và o tròn ở phía bên kia: Đây là trường hợp khi có một phân phối dữ liệu không đồng nhất.
# Box với line thể hiện phần trung bình của dữ liệu, trong khi o tròn biểu thị sự không đồng nhất hoặc các giá trị bất thường nằm ở phía bên kia.
#4. Dạng có 2 line và ở giữa có 1 box: Đây là trường hợp khi dữ liệu được chia thành hai phân nhóm và
# box ở giữa biểu thị phần trung bình của mỗi phân nhóm.
#5. Dạng có 2 line ở 2 bên và 1 box bị chia đôi: Đây là trường hợp khi dữ liệu được chia thành hai phân nhóm và
# box bị chia đôi biểu thị phần trung bình của mỗi phân nhóm.
#6. Dạng có 2 o tròn bên trái chia đôi bằng 1 line dọc và 4 o tròn bên phải: Đây là trường hợp khi dữ liệu được chia thành hai phân nhóm, và
# mỗi phân nhóm có các outliers riêng biệt.
#7. Dạng bên trái có line và 1 box rất to bên phải hoặc ngược lại: Đây là trường hợp khi dữ liệu không đồng nhất và
# có một phân nhóm có độ phân tán lớn hơn phân nhóm còn lại.
#8. Dạng có 1 box duy nhất to và có 1 đường line dọc chia đôi ở giữa: Đây là trường hợp khi dữ liệu có một phân nhóm duy nhất và
# đường line dọc chia đôi biểu thị phần trung bình của phân nhóm này.
#9. Dạng có 1 box duy nhất to và có 1 đường line dọc chia đôi lệch bên trái hoặc bên phải: Đây là trường hợp khi dữ liệu có một phân nhóm duy nhất và
# đường line dọc chia đôi lệch biểu thị phần trung bình của phân nhóm này.
#Tuy nhiên, để hiểu rõ hơn về các biểu đồ và ý nghĩa của chúng, nên xem xét kết hợp với các thông số thống kê khác và
# kiến thức về lĩnh vực dữ liệu của bạn.
#-->Result Analysis Insight ()
# TB: (1,2),3), 4), (5),(6),(7, (9, (10, (12), 13), (14, (15, 16), (18, (19), (20, (21, 22) 23), (25),(26), 27), (31, 34), (35), 36), 37), (38, (41, 45)
# 2:O: 8)
# 1TB + 1P:0 : (32, (44
# 2T:0 + | + 4P:0: (11
# 1T:0 + | + 2P:0: (17
# 1T:0 + 1TB + 1P:0:
# 1T:0 + 1TB : 28), 24), 33)
# 2T:0 + 1TB : 30)
# 1TB + 2P:0 :
# 1TB + 1 TB + 2P:0: (29
# 3T:0 + 1TB : 39), 40)
# | + 2P:0 : (42
# 2T:0 + | + 1P:0 : 43)
# --> TB -->
#S1: 01 .. 5,
#S2: 6 .. 12,
#S3: 13 .. 19,
#S4: 20 .. 25,
#S5: 26 .. 35,
#-------------
4. Các Hàm thủ tục Thống kê và Phân tích Dữ liệu --> Analytics/Statistic Data
4.4. Hàm sns.scatterplot so sánh với Giá trị thực để xác định một độ phân bố và độ thay đổi dữ liệu số Chú thích: hàm sns.scatterplot. Hàm này trong thư viện Seaborn được sử dụng để tạo biểu đồ phân tán (scatter plot), giúp chúng ta quan sát và so sánh mối quan hệ giữa hai biến dữ liệu số.Biểu đồ phân tán biểu thị các điểm dữ liệu trên một không gian hai chiều, trong đó mỗi điểm dữ liệu được đại diện bởi một điểm trên biểu đồ. Trục x và trục y thường biểu thị hai biến dữ liệu mà chúng ta muốn so sánh. Điểm dữ liệu trên biểu đồ phân tán có thể có các mức độ tương quan khác nhau, từ tương quan dương (các điểm tăng theo cùng một hướng) đến tương quan âm (các điểm giảm theo cùng một hướng) và không có tương quan.
Biểu đồ phân tán giúp chúng ta đánh giá mức độ phân bố và độ thay đổi của dữ liệu số. Nó cho phép chúng ta xem xét các mẫu dữ liệu và tìm hiểu mối quan hệ giữa các biến số. Bằng cách xem xét biểu đồ phân tán, chúng ta có thể nhận ra các mẫu, xu hướng và sự biến đổi trong dữ liệu.
Tóm lại, hàm sns.scatterplot cho phép chúng ta so sánh và phân tích mối quan hệ giữa hai biến số, từ đó xác định được độ phân bố và độ thay đổi của dữ liệu số.
for i in ['S01', 'S02', 'S03', 'S04', 'S05', 'S06', 'S07', 'S08', 'S09',
'S10', 'S11', 'S12', 'S13', 'S14', 'S15', 'S16', 'S17', 'S18', 'S19',
'S20', 'S21', 'S22', 'S23', 'S24', 'S25', 'S26', 'S27', 'S28', 'S29',
'S30', 'S31', 'S32', 'S33', 'S34', 'S35', 'S36', 'S37', 'S38', 'S39',
'S40', 'S41', 'S42', 'S43', 'S44', 'S45']:
plt.figure(figsize=(15,6))
sns.scatterplot(data=df,y='Date',x=i)
plt.grid()
plt.show()
4. Các Hàm thủ tục Thống kê và Phân tích Dữ liệu --> Analytics/Statistic Data
4.6. Thư viện networkx và các hàm như nx.Graph(), add_node(), spring_layout(), và draw_networkx() được kết hợp để làm việc với đồ thị (graph) và vẽ đồ thị một cách trực quan. Chú thích: - Thư viện networkx cung cấp các công cụ và chức năng để làm việc với các loại đồ thị, bao gồm đồ thị vô hướng, đồ thị có hướng, đồ thị đa đỉnh và đa cung, và nhiều hơn nữa. Một trong những đối tượng quan trọng trong networkx là lớp Graph() để tạo và quản lý đồ thị. - Hàm add_node() được sử dụng để thêm đỉnh (node) vào đồ thị. Trong ví dụ của bạn, add_node(f"{i+1}.{j+1}", label=number) thêm một đỉnh vào đồ thị với tên là f"{i+1}.{j+1}" và thuộc tính label có giá trị là number. - Hàm spring_layout() được sử dụng để xác định vị trí của các đỉnh trong đồ thị bằng phương pháp spring layout. Nó sắp xếp các đỉnh sao cho các đỉnh có mối quan hệ gần nhau sẽ được đặt gần nhau hơn trên không gian. - Cuối cùng, hàm draw_networkx() được sử dụng để vẽ đồ thị trực quan dựa trên các thông tin về đỉnh và cung đã được thêm vào đồ thị. Nó tạo ra một biểu đồ với đỉnh và cung được hiển thị một cách rõ ràng và trực quan. Vì vậy, bằng cách kết hợp thư viện networkx và các hàm như nx.Graph(), add_node(), spring_layout(), và draw_networkx(), chúng ta có thể tạo và quản lý đồ thị, xác định vị trí của các đỉnh trong đồ thị, và vẽ đồ thị một cách trực quan để hiển thị mối quan hệ giữa các đỉnh.import networkx as nx
import matplotlib.pyplot as plt
# Tạo đồ thị
G = nx.Graph()
# Thêm các nút vào đồ thị
sequences = [
# Lap bang Chart Vietlott.vn > Chart Cluster Stack M6B45 (21.1.2024)
[60,61,62,63,64,65,66,67,68,69], #x0
[8,15,20,24,43,44], #1
[14,19,21,36], #2
[2,42], #3
[10,11,27,39], #4 --> 1 node (40) older
[12,18,29,], #5
[3,4,45], #6
[9,16,31,33], #7
[40 ], #8 --> bỏ 8?, 29?
[23,25,34], #9 --> 1 node (21, 32) older
[22,35,37], #10
[ ], #11
[1,5,24,42], #12 --> 1 node (36) vs 1 node (25,23) vs --> 1 node (26,37,45,6,4,39,24,27) bỏ 13?,26, 37, 14?, 4,6, 12?, 15?,11?,10?
[13,38], #13 --> 1 node (26,37,45,6,4,39,24,27) bỏ 13?,
[32], #14 --> 1 node (26,37,45,6,4,39,24,27) bỏ 14?,
[7], #15--> 1 node (26,37,45,6,4,39,24,27) bỏ 15? 26?
[], #16
[28 ], #17 --> 1 node (30)
[17,41], #18
[], #19--> 1 node (13) --> bỏ 19?
[ ], #20
[], #21
[], #22
[], #23
[], #24
[6], #25
[], #26
[26], #27 --> 1 node (35)
[], #28
[30], #29
[], #30
[], #31
[], #32
[], #33
[], #34
[], #35 --> 1 node (8)
]
for i, sequence in enumerate(sequences):
for j, number in enumerate(sequence):
G.add_node(f"{i+1}.{j+1}", label=number)
# Thêm các cạnh cho quan hệ hình cây số học
for i in range(len(sequences)-1):
for j in range(len(sequences[i])):
G.add_edge(f"{i+1}.{j+1}", f"{i+2}.{j//2+1}")
# Vẽ đồ thị
pos = nx.spring_layout(G) # Vị trí các nút
labels = nx.get_node_attributes(G, 'label') # Nhãn của các nút
plt.figure(figsize=(12, 8))
nx.draw_networkx(G, pos, labels=labels, node_size=200, font_size=10, font_color='red', node_color='none', edge_color='gray', linewidths=1)
plt.axis('off')
plt.tight_layout() # Tự động điều chỉnh khoảng cách giữa các nút
plt.show()
# quay ngau nhien lay ra 3 so (6.12.2023 15:00 pm)
"25 3 32 29 10 22"
"21 34 29 18 5 6"
"30 10 33 17 19 34"
import random
#0
#print(random.randrange(7,44))
class Node:
def __init__(self, value):
self.value = value
self.left = None
self.right = None
self.center = None
def postorder_traversal(node):
if node is None:
return
# Duyệt cây con bên trái của nút
postorder_traversal(node.left)
# Duyệt cây con bên phải của nút
postorder_traversal(node.right)
# Duyệt cây con bên phải của nút
postorder_traversal(node.center)
# In giá trị của nút
print(node.value, end=" ")
# Tạo cây theo thứ tự đã mô tả
root = Node("11 15 16 17 42 43,")
root.left = Node("18 19 20 29 41,")
root.right = Node("12 14 21 32,")
root.left.left = Node("5 10 27,")
root.left.right = Node("9 22 24 38 39,")
root.left.center = Node("4 6 23 25 36,")
root.right.center = Node("34 45,")
root.right.left = Node("1 37,")
root.right.right = Node("3 26 2 7 8 13 28 30 31 33 35 40 44, ")
# Thực hiện truyền tải theo thứ tự sau
postorder_traversal(root)
#- Lap bang Chart Vietlott.vn > Chart Cluster Stack M6B45
# + chọn Liên tiếp tăng 1 kỳ gần nhất: 12, 14, 16, 21, 29, 32,
# + chọn liên tiếp tăng 2 kỳ gần nhất: 5, 10, 27,
# + chọn liên tiếp tăng sau 3 kỳ gần nhất: 9, 22, 24, 38, 39,
# + chọn liên tiếp tăng sau 4 kỳ gần nhất: 4, 6, 15, 23, 25, 36,
# + chọn liên tiếp tăng sau 5 kỳ gần nhất: 18, 34, 41, 45
# + chọn liên tiếp tăng sau 6 kỳ gần nhất: 20, 37
# + chọn liên tiếp tăng sau 7 kỳ gần nhất: 1, 19, 26
# + chọn liên tiếp tăng sau 8 kỳ gần nhất: ,
# + chọn liên tiếp tăng sau 9 kỳ gần nhất: 2, 30,
# + chọn liên tiếp tăng sau 10 kỳ gần nhất: 7, 8, 11, 13, 17, 28, 31, 33, 35, 40, 42, 43, 44
# Lay chọn số theo Tử vi ngày / tuổi hợp số may mắn: ví dụ: 1,3,9 + 0,8,10
import random
#0
print(random.randrange(12,32))
#1
print(random.randrange(2,32))
#2
#print(random.randrange(9,42))
#3
print(random.randrange(1,36))
#4
#print(random.randrange(2,45))
#5
#print(random.randrange(15,39))
#6
#print(random.randrange(1,34))
#7
#print(random.randrange(16,41))
#8
print(random.randrange(2,37))
#9
print(random.randrange(2,31))
#10
print(random.randrange(1,44))
#https://matplotlib.org/stable/plot_types/basic/stem.html#sphx-glr-plot-types-basic-stem-py
import matplotlib.pyplot as plt
import numpy as np
plt.style.use('_mpl-gallery')
# make data
x = 0.5 + np.arange(8)
y = [4.8, 5.5, 3.5, 4.6, 6.5, 6.6, 2.6, 3.0]
# plot
fig, ax = plt.subplots()
ax.stem(x, y)
ax.set(xlim=(0, 8), xticks=np.arange(1, 8),
ylim=(0, 8), yticks=np.arange(1, 8))
plt.show()
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
well_data1 = pd.read_csv(r"C:\Python311\workspaces\m6B45.csv")
pd.set_option("display.max_rows",df.shape[0]+1)
well_data1 = well_data1[['S01', 'S02', 'S03', 'S04', 'S05', 'S06', 'S07', 'S08', 'S09', 'S10', 'S11', 'S12']]
figure = plt.figure(figsize=(15,5))
sns.heatmap(well_data1)
plt.show()
corr = well_data1.corr()
corr
sns.heatmap(corr, cmap='RdBu', vmin=0, vmax=1, annot=True, annot_kws={'fontsize':8})
well_data2 = pd.read_csv(r"C:\Python311\workspaces\m6B45.csv")
pd.set_option("display.max_rows",df.shape[0]+1)
well_data2 = well_data2[['S12', 'S13', 'S14', 'S15', 'S16', 'S17', 'S18', 'S19']]
figure = plt.figure(figsize=(15,5))
sns.heatmap(well_data2)
plt.show()
corr = well_data2.corr()
corr
sns.heatmap(corr, cmap='RdBu', vmin=0, vmax=1, annot=True, annot_kws={'fontsize':8})
well_data3 = pd.read_csv(r"C:\Python311\workspaces\m6B45.csv")
pd.set_option("display.max_rows",df.shape[0]+1)
well_data3 = well_data3[['S19','S20', 'S21', 'S22', 'S23', 'S24', 'S25', 'S26']]
figure = plt.figure(figsize=(15,5))
sns.heatmap(well_data3)
plt.show()
corr = well_data3.corr()
corr
sns.heatmap(corr, cmap='RdBu', vmin=0, vmax=1, annot=True, annot_kws={'fontsize':8})
well_data4 = pd.read_csv(r"C:\Python311\workspaces\m6B45.csv")
pd.set_option("display.max_rows",df.shape[0]+1)
well_data4 = well_data4[['S26','S27','S28','S29','S30', 'S31', 'S32', 'S33', 'S34']]
figure = plt.figure(figsize=(15,5))
sns.heatmap(well_data4)
plt.show()
corr = well_data4.corr()
corr
sns.heatmap(corr, cmap='RdBu', vmin=0, vmax=1, annot=True, annot_kws={'fontsize':8})
well_data5 = pd.read_csv(r"C:\Python311\workspaces\m6B45.csv")
pd.set_option("display.max_rows",df.shape[0]+1)
well_data5 = well_data5[['S34', 'S35', 'S36']]
figure = plt.figure(figsize=(15,5))
sns.heatmap(well_data5)
plt.show()
corr = well_data5.corr()
corr
sns.heatmap(corr, cmap='RdBu', vmin=0, vmax=1, annot=True, annot_kws={'fontsize':8})
well_data6 = pd.read_csv(r"C:\Python311\workspaces\m6B45.csv")
pd.set_option("display.max_rows",df.shape[0]+1)
well_data6 = well_data6[['S36','S37','S38','S39','S40','S41','S42','S43','S44','S45']]
figure = plt.figure(figsize=(15,5))
sns.heatmap(well_data6)
plt.show()
corr = well_data6.corr()
corr
sns.heatmap(corr, cmap='RdBu', vmin=0, vmax=1, annot=True, annot_kws={'fontsize':8})
4. Các Hàm thủ tục Thống kê và Phân tích Dữ liệu --> Analytics/Statistic Data
4.6. Thư viện networkx và các hàm như nx.Graph(), add_node(), spring_layout(), và draw_networkx() được kết hợp để làm việc với đồ thị (graph) và vẽ đồ thị một cách trực quan. Chú thích: - Thư viện networkx cung cấp các công cụ và chức năng để làm việc với các loại đồ thị, bao gồm đồ thị vô hướng, đồ thị có hướng, đồ thị đa đỉnh và đa cung, và nhiều hơn nữa. Một trong những đối tượng quan trọng trong networkx là lớp Graph() để tạo và quản lý đồ thị. - Hàm add_node() được sử dụng để thêm đỉnh (node) vào đồ thị. Trong ví dụ của bạn, add_node(f"{i+1}.{j+1}", label=number) thêm một đỉnh vào đồ thị với tên là f"{i+1}.{j+1}" và thuộc tính label có giá trị là number. - Hàm spring_layout() được sử dụng để xác định vị trí của các đỉnh trong đồ thị bằng phương pháp spring layout. Nó sắp xếp các đỉnh sao cho các đỉnh có mối quan hệ gần nhau sẽ được đặt gần nhau hơn trên không gian. - Cuối cùng, hàm draw_networkx() được sử dụng để vẽ đồ thị trực quan dựa trên các thông tin về đỉnh và cung đã được thêm vào đồ thị. Nó tạo ra một biểu đồ với đỉnh và cung được hiển thị một cách rõ ràng và trực quan. Vì vậy, bằng cách kết hợp thư viện networkx và các hàm như nx.Graph(), add_node(), spring_layout(), và draw_networkx(), chúng ta có thể tạo và quản lý đồ thị, xác định vị trí của các đỉnh trong đồ thị, và vẽ đồ thị một cách trực quan để hiển thị mối quan hệ giữa các đỉnh.import networkx as nx
import matplotlib.pyplot as plt
# Tạo đồ thị
G = nx.Graph()
# Thêm các nút vào đồ thị
sequences = [
[61,62,63,64,65,66], #x0
[19], #1--> bỏ 40, 29,14,9
[13,44], #2--> bỏ 34,23,25
[16,35,37], #3 --> bỏ 39,22
[], #4 --> bỏ 36,8
[1,5,24], #5 --> bỏ 43,2
[], #6--> bỏ 38,12
[], #7--> bỏ 32,21,15
[7,18], #8 --> bỏ 33, 31,3
[10], #9 -->bỏ 11,
[], #10--> bỏ 28
[41], #11,17
[], #12 --> bỏ 42
[], #13
[], #14
[], #15--> bỏ 27
[], #16
[], #17--> bỏ 4,6
[], #18--> bỏ 45
[], #19
[], #20--> bỏ 26
[], #21
[], #22--> bỏ 30
[], #23
[], #24
[], #25
[], #26
[], #27
[], #28
[], #29
[], #30
[], #31
[], #32
[], #33
[], #34
[], #35
]
for i, sequence in enumerate(sequences):
for j, number in enumerate(sequence):
G.add_node(f"{i+1}.{j+1}", label=number)
# Thêm các cạnh cho quan hệ hình cây số học
for i in range(len(sequences)-1):
for j in range(len(sequences[i])):
G.add_edge(f"{i+1}.{j+1}", f"{i+2}.{j//2+1}")
# Vẽ đồ thị
pos = nx.spring_layout(G) # Vị trí các nút
labels = nx.get_node_attributes(G, 'label') # Nhãn của các nút
plt.figure(figsize=(12, 8))
nx.draw_networkx(G, pos, labels=labels, node_size=200, font_size=10, font_color='red', node_color='none', edge_color='gray', linewidths=1)
plt.axis('off')
plt.tight_layout() # Tự động điều chỉnh khoảng cách giữa các nút
plt.show()
#Tập hợp của cả A và B xử lý Sortlist, Postpose, deduplicate numbers:
#A: [13,16,19,35,44] vs [7,10,18]
#B: [20,13,19,16,23,22,44,25] vs [18,10,7,21]
#--> 7 10 13 16 18 19 20 21 22 23 25 35 44
#viết hàm python ngẫu nhiên liên tiếp để chọn ra 6 số ngẫu nhiên không trùng duy nhất và tăng dần trong dãy số trên ?
#Để chọn ra 6 số ngẫu nhiên không trùng lặp và tăng dần từ dãy số đã cho, bạn có thể thực hiện các bước sau:
#1. Sắp xếp dãy số theo thứ tự tăng dần.
#2. Chọn 6 số ngẫu nhiên từ dãy số đã sắp xếp.
#Dưới đây là một hàm Python để thực hiện công việc này:
import random
def choose_random_numbers(sequence, k):
sorted_sequence = sorted(sequence) # Sắp xếp dãy số theo thứ tự tăng dần
random_numbers = random.sample(sorted_sequence, k) # Chọn ngẫu nhiên k số từ dãy số đã sắp xếp
return random_numbers
sequence = [7,10,13,16,18,19,20,21,22,23,25,35,44]
k = 6
random_numbers = choose_random_numbers(sequence, k)
print(random_numbers)
# --> Bấm 5 lần chọn: [35, 7, 13, 23, 25, 10]
[35, 7, 13, 23, 25, 10]
#20.12.2023 --> [15, 1, 13, 16, 6, 3], [13, 34, 20, 1, 3, 4], [16, 34, 26, 10, 6, 12]
#24.12.2023 --> [7, 28, 2, 34, 3, 40] [44, 18, 2, 16, 38, 1] [3, 44, 41, 9, 5, 18]
#5.1.2024 --> [35, 7, 13, 23, 25, 10]
import pandas as pd
from itertools import combinations
# Đọc dữ liệu từ file CSV
data = pd.read_csv(r"C:\Python311\workspaces\m6B45.csv")
# Xóa cột 'Date' và chuyển đổi thành ma trận numpy
X = data.iloc[:, 1:].values
# Tính tổng số lần xuất hiện của mỗi số từ 1 đến 45
sum_counts = X.sum(axis=0)
# Tìm ra 6 số có khả năng cao nhất không trùng nhau
top_6_nums = []
for _ in range(6):
max_index = sum_counts.argmax()
top_6_nums.append(max_index + 1)
sum_counts[max_index] = 0
# In ra 6 số có khả năng cao nhất không trùng nhau
print("6 số có khả năng cao nhất không trùng nhau:", top_6_nums)
6 số có khả năng cao nhất không trùng nhau: [44, 19, 24, 4, 37, 30]
4. Các Hàm thủ tục Thống kê và Phân tích Dữ liệu --> Analytics/Statistic Data
4.8. Hàm Đồ Thị nhiệt - Heatmap() làm việc với biểu đồ heatmap (đồ thị nhiệt) và tính toán ma trận tương quan của dữ liệu đầu vào. Mục đích chính của đoạn mã này là: - Đọc dữ liệu từ tệp CSV: Dữ liệu được đọc từ tệp CSV với đường dẫn đã cho sử dụng hàm pd.read_csv() và lưu vào biến well_data6. Thiết lập tùy chọn hiển thị: Sử dụng hàm pd.set_option() để thiết lập tùy chọn hiển thị, trong trường hợp này là display.max_rows. Giá trị của display.max_rows được thiết lập là số hàng trong df cộng 1. - Lựa chọn các cột dữ liệu: Dữ liệu trong well_data6 được lựa chọn chỉ bao gồm các cột 'S1' đến 'S45' bằng cách truy cập vào well_data6 và chỉ định danh sách tên các cột. - Tạo biểu đồ heatmap: Một đối tượng hình ảnh (figure) được tạo ra với kích thước 15x5 sử dụng plt.figure(figsize=(15,5)). Biểu đồ heatmap được tạo ra sử dụng hàm sns.heatmap() và dữ liệu từ well_data6. Điều này tạo ra một biểu đồ nhiệt với các giá trị dữ liệu được màu sắc hóa và hiển thị trên màn hình. - Tính toán ma trận tương quan: Sử dụng well_data6.corr(), ma trận tương quan của dữ liệu trong well_data6 được tính toán và lưu vào biến corr. - Vẽ biểu đồ heatmap của ma trận tương quan: Sử dụng hàm sns.heatmap() một lần nữa, biểu đồ heatmap của ma trận tương quan được vẽ. - Trong trường hợp này, biểu đồ heatmap được màu sắc bằng cmap 'RdBu' (Red-Blue colormap), giá trị tối thiểu và tối đa của màu sắc được đặt là 1, các giá trị tương quan được chú thích trên biểu đồ và cỡ chữ của chú thích được đặt là 8. - Tóm lại, đoạn mã trên được sử dụng để tạo biểu đồ heatmap của dữ liệu từ tệp CSV và tính toán ma trận tương quan của dữ liệu đó. Mục đích của nó là trực quan hóa dữ liệu và hiển thị mối quan hệ tương quan giữa các cột dữ liệu trong biểu đồ heatmap.#[44, 19, 24, 4, 37, 30]
well_data6 = pd.read_csv(r"C:\Python311\workspaces\m6B45.csv")
pd.set_option("display.max_rows",df.shape[0]+1)
well_data6 = well_data6[['S01','S02','S03','S04','S05','S06','S07','S08','S09','S10','S11','S12','S13','S14','S15','S16','S17','S18','S19','S20','S21','S22','S23','S24','S25','S26','S27','S28','S29','S30','S31','S32','S33','S34','S35','S36','S37','S38','S39','S40','S41','S42','S43','S44','S45']]
figure = plt.figure(figsize=(15,5))
sns.heatmap(well_data6)
#plt.show()
corr = well_data6.corr()
corr
sns.heatmap(corr, cmap='RdBu', vmin=1, vmax=1, annot=True, annot_kws={'fontsize':8})
<Axes: >
import networkx as nx
import matplotlib.pyplot as plt
# Tạo đồ thị
G = nx.Graph()
# Thêm các nút vào đồ thị
sequences = [
# Lap bang Chart Vietlott.vn > Chart Cluster Stack M6B45 (5.1.2024)
[61,62,63,64,65,66], #x0
[19,20], #1 --> bỏ 9,14, 29,40
[13,23,25,44], #2 --> bỏ 34
[16,22,35,37], #3--> bỏ 39
[], #4 --> bỏ 8,36
[1,5,24], #5--> bỏ 2,43
[], #6 --> bỏ 12,38
[21], #7 --> bỏ 15,32
[7,18], #8 --> bỏ 3,31,33
[10], #9 --> bỏ 11
[], #10 --> bỏ 28
[41], #11 --> bỏ 17
[], #12 --> bỏ 42
[], #13 --> 1 node (26,37,45,6,4,39,24,27) bỏ 13?,
[], #14 --> 1 node (26,37,45,6,4,39,24,27) bỏ 14?,
[27], #15--> 1 node (26,37,45,6,4,39,24,27) bỏ 15? 26?
[], #16
[4,6], #17 --> 1 node (30)
[], #18 --> bỏ 45
[], #19--> 1 node (13) --> bỏ 19?
[], #20 --> bỏ 26
[], #21
[30], #22
[], #23
[], #24
[], #25
[], #26
[], #27 --> 1 node (35)
[], #28
[], #29
[], #30
[], #31
[], #32
[], #33
[], #34
[], #35 --> 1 node (8)
]
for i, sequence in enumerate(sequences):
for j, number in enumerate(sequence):
G.add_node(f"{i+1}.{j+1}", label=number)
# Thêm các cạnh cho quan hệ hình cây số học
for i in range(len(sequences)-1):
for j in range(len(sequences[i])):
G.add_edge(f"{i+1}.{j+1}", f"{i+2}.{j//2+1}")
# Vẽ đồ thị
pos = nx.spring_layout(G) # Vị trí các nút
labels = nx.get_node_attributes(G, 'label') # Nhãn của các nút
plt.figure(figsize=(12, 8))
nx.draw_networkx(G, pos, labels=labels, node_size=200, font_size=10, font_color='red', node_color='none', edge_color='gray', linewidths=1)
plt.axis('off')
plt.tight_layout() # Tự động điều chỉnh khoảng cách giữa các nút
plt.show()
#Tập hợp của cả A và B xử lý Sortlist, Postpose, deduplicate numbers:
#A: [13,16,19,35,44] vs [7,10,18]
#B: [20,13,19,16,23,22,44,25] vs [18,10,7,21]
#--> 7 10 13 16 18 19 20 21 22 23 25 35 44
#D: [10,16,22,44,19,32,20]
#E: [44, 19, 24, 4, 37, 30]
#--> [4,7,10,13,16,18,19,20,21,22,23,24,25,30,32,35,37,44]
#viết hàm python ngẫu nhiên liên tiếp để chọn ra 6 số ngẫu nhiên không trùng duy nhất và tăng dần trong dãy số trên ?
#Để chọn ra 6 số ngẫu nhiên không trùng lặp và tăng dần từ dãy số đã cho, bạn có thể thực hiện các bước sau:
#1. Sắp xếp dãy số theo thứ tự tăng dần.
#2. Chọn 6 số ngẫu nhiên từ dãy số đã sắp xếp.
#Dưới đây là một hàm Python để thực hiện công việc này:
import random
def choose_random_numbers(sequence, k):
sorted_sequence = sorted(sequence) # Sắp xếp dãy số theo thứ tự tăng dần
random_numbers = random.sample(sorted_sequence, k) # Chọn ngẫu nhiên k số từ dãy số đã sắp xếp
return random_numbers
sequence = [4,7,10,13,16,18,19,20,21,22,23,24,25,30,32,35,37,44]
k = 6
random_numbers = choose_random_numbers(sequence, k)
print(random_numbers)
# -->5.1.2024: Bấm 5 lần chọn: [35, 7, 13, 23, 25, 10]
# -->5.1.2024: Bấm 7 lần chọn A,B,D,E: [7, 25, 10, 23, 24, 13]
[20, 16, 44, 37, 22, 21]
4. Các Hàm thủ tục Thống kê và Phân tích Dữ liệu --> Analytics/Statistic Data
4.7. Một biểu đồ phân tán (scatter plot) với sự sử dụng của thư viện Matplotlib Mục đích chính của đoạn mã này là: - Tạo dữ liệu ngẫu nhiên: Đầu tiên, dữ liệu ngẫu nhiên được tạo ra với 3 chiều (x, y, scale). Biến x và y chứa các giá trị ngẫu nhiên từ danh sách đã cho, còn biến scale chứa các giá trị ngẫu nhiên từ danh sách đã cho nhưng được nhân với 3. - Tạo đồ thị: Một đối tượng hình ảnh (figure) và trục (axes) được tạo ra sử dụng hàm plt.subplots(). Kích thước của hình ảnh được thiết lập theo kích thước cửa sổ màn hình. Điều này đảm bảo rằng biểu đồ sẽ phù hợp với kích thước hiển thị trên màn hình. - Vẽ biểu đồ phân tán: Sử dụng hàm ax.scatter(), biểu đồ phân tán được vẽ với các điểm dữ liệu được xác định bởi các giá trị x, y và scale. Màu sắc của các điểm được xác định bởi scale và kích thước của các điểm được xác định bởi giá trị tuyệt đối của scale nhân với 3. - Thiết lập tiêu đề và nhãn trục: Tiêu đề của biểu đồ được đặt là "Some random data, created with JupyterLab!". Các nhãn trục x và y được thiết lập bằng cách sử dụng các giá trị duy nhất từ dữ liệu x và y. - Đặt tỉ lệ và lưới: Tỉ lệ của trục y được đặt là 'auto', tạo ra một biểu đồ có tỉ lệ tự động. Lưới được thêm vào biểu đồ bằng cách sử dụng hàm plt.grid(). -Hiển thị biểu đồ: Cuối cùng, biểu đồ được hiển thị bằng cách sử dụng hàm plt.show(). -Tóm lại, đoạn mã trên được sử dụng để tạo ra một biểu đồ phân tán với dữ liệu ngẫu nhiên, mô tả các giá trị của x, y và scale. Mục đích của nó là trực quan hóa dữ liệu và hiển thị biểu đồ phân tán trên màn hình.from matplotlib import pyplot as plt
import numpy as np
# Generate 100 random data points along 3 dimensions, ranging from 1 to 45
x = np.random.choice([2, 3, 5, 7, 11, 13, 17, 19, 23, 27, 31, 37, 41, 43], size=45)
y = np.random.choice([2, 3, 5, 7, 11, 13, 17, 19, 23, 27, 31, 37, 41, 43], size=45)
scale = np.random.choice([2, 3, 5, 7, 11, 13, 17, 19, 23, 27, 31, 37, 41, 43], size=45)
fig, ax = plt.subplots()
# Map each onto a scatterplot we'll create with Matplotlib
ax.scatter(x=x, y=y, c=scale, s=np.abs(scale)*10)
ax.set(title="Some random data, created with JupyterLab!")
plt.show()
CHỮ IN HOA VÀ ĐÂM
MARKDOWN TRONG JUPYTER NOTEBOOK¶
Đây là một đoạn văn bản viết hoa, đậm, kích thước font > 14pt, màu chữ đỏ, nền vàng.
Youtube:
Bạn có thể thay thế `https://example.com/iframe_url1` và `https://example.com/iframe_url2` bằng các URL iframe thực tế bạn muốn nhúng.`
Trong đó, `VIDEO_ID` là ID duy nhất của video YouTube bạn muốn nhúng. Bạn có thể sao chép liên kết nhúng từ YouTube bằng cách nhấp vào nút "Chia sẻ" dưới video và sau đó chọn "Nhúng".
#https://matplotlib.org/stable/plot_types/basic/scatter_plot.html
import matplotlib.pyplot as plt
import numpy as np
plt.style.use('_mpl-gallery')
# make the data
np.random.seed(3)
sequence = [7,10,13,16,18,19,20,21,22,23,25,35,44]
x = np.array(sequence)
y = 4 + np.random.normal(0, 1, len(x))
sizes = np.random.uniform(30, 80, len(x))
colors = np.random.uniform(30, 80, len(x))
indices = np.argsort(sizes)[-10:]
x = x[indices]
y = y[indices]
sizes = sizes[indices]
colors = colors[indices]
# set the figure size
fig = plt.figure(figsize=(8, 8)) # Adjust the width and height as needed
# plot
ax = fig.add_subplot(111)
ax.scatter(x, y, s=sizes, c=colors, vmin=0, vmax=100)
ax.set(xlim=(0, 50), xticks=np.arange(1, 46, 1),
ylim=(0, 50), yticks=np.arange(1, 46, 1))
plt.show()
5. Các Hàm thủ tục nâng cao trong kiểm toán Thống kê và Phân tích Dữ liệu --> Analytics/Statistic Data:
- Rating đánh giá: - Xác định quan hệ giữa các số đã chọn theo chuỗi Thời gian - Mật độ Số đã chọn Desity - Xác định 7 số có khả năngimport numpy as np
import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
df = pd.read_csv(r"C:\Python311\workspaces\m6B45.csv")
latest_date = '2024-02-07'
def analyze_lottery_numbers(df, latest_date):
pd.set_option("display.max_rows", df.shape[0]+1)
pd.set_option("display.max_columns", 60)
numbers = ['S01', 'S02', 'S03', 'S04', 'S05', 'S06', 'S07', 'S08', 'S09',
'S10', 'S11', 'S12', 'S13', 'S14', 'S15', 'S16', 'S17', 'S18', 'S19',
'S20', 'S21', 'S22', 'S23', 'S24', 'S25', 'S26', 'S27', 'S28', 'S29',
'S30', 'S31', 'S32', 'S33', 'S34', 'S35', 'S36', 'S37', 'S38', 'S39',
'S40', 'S41', 'S42', 'S43', 'S44', 'S45']
# Tạo một mảng màu tùy chỉnh với màu sắc tương phản rõ ràng
custom_palette = ['#FF0000', '#00FF00', '#0000FF', '#FFFF00', '#FF00FF', '#00FFFF', '#FF8000', '#8000FF', '#00FF80',
'#808080', '#800000', '#008000', '#000080', '#808000', '#800080', '#008080', '#C0C0C0', '#FF8080',
'#80FF80', '#8080FF', '#FFFF80', '#FF80FF', '#80FFFF', '#FFBF00', '#BF00FF', '#00FFBF', '#A0A0A0',
'#BF0000', '#00BF00', '#0000BF', '#BFBF00', '#BF00BF', '#00BFBF', '#404040', '#400000', '#004000',
'#000040', '#404000', '#400040', '#004040', '#606060', '#400000', '#004000', '#000040', '#606000',
'#606040', '#004060', '#808080', '#004000', '#000040', '#400040']
plt.figure(figsize=(12, 10))
for i, number in enumerate(numbers):
sns.scatterplot(data=df, y='Date', x=number, color=custom_palette[i], label=number)
plt.grid()
# Tạo biểu đồ màu sắc như thanh màu sắc bên cạnh biểu đồ chính
color_legend = [plt.Line2D([0], [0], marker='o', color='w', markerfacecolor=custom_palette[i], markersize=10) for i in range(len(numbers))]
plt.legend(color_legend, numbers, title='Numbers', loc='lower center', bbox_to_anchor=(0.5, -0.25), ncol=9)
plt.show()
analyze_lottery_numbers(df, latest_date)
#Tập hợp 135 - 136 scores:
import random
def choose_random_numbers(sequence, k):
sorted_sequence = sorted(sequence) # Sắp xếp dãy số theo thứ tự tăng dần
random_numbers = random.sample(sorted_sequence, k) # Chọn ngẫu nhiên k số từ dãy số đã sắp xếp
return random_numbers
sequence = [38,42]
k = 1
random_numbers = choose_random_numbers(sequence, k)
print(random_numbers)
#Tập hợp 139 scores:
import random
def choose_random_numbers(sequence, k):
sorted_sequence = sorted(sequence) # Sắp xếp dãy số theo thứ tự tăng dần
random_numbers = random.sample(sorted_sequence, k) # Chọn ngẫu nhiên k số từ dãy số đã sắp xếp
return random_numbers
sequence = [17]
k = 0
random_numbers = choose_random_numbers(sequence, k)
print(random_numbers)
#Tập hợp 141 - 143 scores:
import random
def choose_random_numbers(sequence, k):
sorted_sequence = sorted(sequence) # Sắp xếp dãy số theo thứ tự tăng dần
random_numbers = random.sample(sorted_sequence, k) # Chọn ngẫu nhiên k số từ dãy số đã sắp xếp
return random_numbers
sequence = [3,12,14,15,32,34,36]
k = 1
random_numbers = choose_random_numbers(sequence, k)
print(random_numbers)
#Tập hợp 145 - 146 scores:
import random
def choose_random_numbers(sequence, k):
sorted_sequence = sorted(sequence) # Sắp xếp dãy số theo thứ tự tăng dần
random_numbers = random.sample(sorted_sequence, k) # Chọn ngẫu nhiên k số từ dãy số đã sắp xếp
return random_numbers
sequence = [2,9,26,29,39,43,45]
k = 1
random_numbers = choose_random_numbers(sequence, k)
print(random_numbers)
#Tập hợp 148 scores:
import random
def choose_random_numbers(sequence, k):
sorted_sequence = sorted(sequence) # Sắp xếp dãy số theo thứ tự tăng dần
random_numbers = random.sample(sorted_sequence, k) # Chọn ngẫu nhiên k số từ dãy số đã sắp xếp
return random_numbers
sequence = [8]
k = 0
random_numbers = choose_random_numbers(sequence, k)
print(random_numbers)
#Tập hợp 150 - 155 scores:
import random
def choose_random_numbers(sequence, k):
sorted_sequence = sorted(sequence) # Sắp xếp dãy số theo thứ tự tăng dần
random_numbers = random.sample(sorted_sequence, k) # Chọn ngẫu nhiên k số từ dãy số đã sắp xếp
return random_numbers
sequence = [11,21,23,25,28,31,33,40,41]
k = 1
random_numbers = choose_random_numbers(sequence, k)
print(random_numbers)
#Tập hợp 158 - 161 scores:
import random
def choose_random_numbers(sequence, k):
sorted_sequence = sorted(sequence) # Sắp xếp dãy số theo thứ tự tăng dần
random_numbers = random.sample(sorted_sequence, k) # Chọn ngẫu nhiên k số từ dãy số đã sắp xếp
return random_numbers
sequence = [1,6,13,16,18,20,22,27,35]
k = 1
random_numbers = choose_random_numbers(sequence, k)
print(random_numbers)
#Tập hợp 165 - 170 scores:
import random
def choose_random_numbers(sequence, k):
sorted_sequence = sorted(sequence) # Sắp xếp dãy số theo thứ tự tăng dần
random_numbers = random.sample(sorted_sequence, k) # Chọn ngẫu nhiên k số từ dãy số đã sắp xếp
return random_numbers
sequence = [4,5,7,10,24,30,37]
k = 1
random_numbers = choose_random_numbers(sequence, k)
print(random_numbers)
#Tập hợp 178 scores:
import random
def choose_random_numbers(sequence, k):
sorted_sequence = sorted(sequence) # Sắp xếp dãy số theo thứ tự tăng dần
random_numbers = random.sample(sorted_sequence, k) # Chọn ngẫu nhiên k số từ dãy số đã sắp xếp
return random_numbers
sequence = [19,44]
k = 1
random_numbers = choose_random_numbers(sequence, k)
print(random_numbers)
[42] [] [14] [39] [] [33] [6] [37] [19]
[38 ít thay đổi][17][15 it thay doi][2][8][28 it thay doi][35][10 it thay doi][44]
#3:[38 ít thay đổi][17][36][29][8][41][20][10 it thay doi][19]
[42][][15 it thay doi][29][][31][20][24][44]
#7: [42][][14][2][8][28 it thay doi][22][10 it thay doi][19]
#9:[38 ít thay đổi][17][12][43][][23][6 it thay doi][24][44]
#11:[42][17 khong dung do duy nhat][14][39][8 khong dung do duy nhất][33][6 it thay doi][37 ít thay đổi][19]
import heapq
class Node:
def __init__(self, value):
self.value = value
self.left = None
self.right = None
def node_tree(node):
pq = []
# Chèn các nút vào Priority Queue
def insert_nodes(node):
if node is None:
return
heapq.heappush(pq, node.value)
insert_nodes(node.left)
insert_nodes(node.right)
insert_nodes(node)
# Xóa các nút từ Priority Queue và đặt lại vào cây
def sort_nodes(node):
if node is None:
return
node.value = heapq.heappop(pq)
sort_nodes(node.left)
sort_nodes(node.right)
sort_nodes(node)
import pandas as pd
from sklearn.linear_model import LogisticRegression
# Đọc dữ liệu từ file CSV
df = pd.read_csv(r"C:\Python311\workspaces\m6b45_s1.csv")
# Chọn các cột cần sử dụng cho việc dự báo
features = ['S45']
target = ['id']
# Xây dựng mô hình hồi quy logistic
model = LogisticRegression()
model.fit(df[features], df[target])
# Dự báo khả năng S1 tăng lên 106 hoặc 107 cho các ngày tiếp theo
future_dates = ['68', '69','70','71']
X_future = pd.DataFrame({'S45': [147,148,149,150]})
predictions = model.predict(X_future)
# In kết quả dự báo
for date, prediction in zip(future_dates, predictions):
print(f'Ngày {date}: Khả năng S45 tăng lên {prediction}')
Ngày 68: Khả năng S45 tăng lên 52 Ngày 69: Khả năng S45 tăng lên 53 Ngày 70: Khả năng S45 tăng lên 53 Ngày 71: Khả năng S45 tăng lên 53
C:\Python311\Lib\site-packages\sklearn\utils\validation.py:1183: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel(). y = column_or_1d(y, warn=True)
6. Hàm nâng cao Quadratic Comparison Method - QCM với ma trận giá trị chữ nhật
import pandas as pd
import matplotlib.pyplot as plt
def qcm_rectangle(matrix):
ratings = []
colors = []
for i in range(2, matrix.shape[1]):
rating = 0
for j in range(2, matrix.shape[1]):
if i == j:
continue
if matrix.iloc[:, i].sum() > matrix.iloc[:, j].sum():
rating += 1
elif matrix.iloc[:, i].sum() < matrix.iloc[:, j].sum():
rating -= 1
ratings.append(rating)
if rating > 0:
colors.append('green')
elif rating < 0:
colors.append('red')
else:
colors.append('gray')
return ratings, colors
# Đọc dữ liệu từ file CSV vào DataFrame
df = pd.read_csv(r"C:\Python311\workspaces\m6b45_s1.csv")
# Gọi hàm QCM và lưu kết quả vào biến ratings và colors
ratings, colors = qcm_rectangle(df)
# Vẽ biểu đồ
plt.figure(figsize=(10, 6))
plt.bar(range(1, 46), ratings, color=colors)
plt.xlabel('Số')
plt.ylabel('Rating')
plt.title('Biểu đồ rating của các số từ S1 đến S45')
plt.show()
Chú thích:
- Cột màu xanh lớn hơn 0: Điều này biểu thị rằng các số hạng có mức độ biến đổi cao hơn so với các số hạng khác. Nó có thể được coi là một rating biến động khó lường, vì những số hạng này có xu hướng thay đổi nhiều trong thời gian. Khi một số hạng có rating dương lớn, điều này có thể đồng nghĩa với việc rủi ro cũng lớn do tính biến động cao của chúng.
- Cột biểu đồ âm, nhỏ hơn 0: Điều này chỉ ra rằng các số hạng có mức độ biến đổi thấp hơn so với các số hạng khác. Rating biến động ít, cho thấy sự ổn định và ít biến thiên trong các số hạng này. Khi một số hạng có rating âm, có thể hiểu là rủi ro cũng ít hơn do tính biến động thấp.
- Cột biểu đồ = 0:Cột biểu đồ = 0: Đây là trường hợp khi các số hạng có mức độ biến đổi trung bình và có sự kiểm soát được. Đây là trường hợp khi các số hạng có mức độ biến đổi trung bình và có sự kiểm soát được. Rating bằng 0 cho thấy tính ổn định với sự cân bằng giữa các số hạng. Tóm lại: biểu đồ QCM ma trận chữ nhật giúp chúng ta đánh giá mức độ biến động của các số hạng trong ma trận. - Các cột màu xanh lớn hơn 0 biểu thị cho biến động cao và rủi ro lớn, trong khi các cột màu đỏ nhỏ hơn 0 biểu thị cho biến động thấp và rủi ro ít. - Cột có rating bằng 0 thể hiện sự ổn định và kiểm soát được của số hạng.